After certain trials and errors, I was able to perform exporting/importing configurations of the layer's attribute table, see Saving and applying layout of columns in QGIS Attribute Table.
Despite a great answer from @KadirŞahbaz, I would like to add some basic details regarding the DOM and XML in the scope of PyQGIS.
The DOM : Document Object Model - defines a standard for accessing and manipulating documents (changing document's structure, style, or content) with a logical tree, e.g. HTML, SVG, or XML. Each branch of the tree ends in a node, and each node contains objects.
The XML DOM - is a standard for getting, changing, adding, and deleting XML elements. It presents an XML document as a tree structure.
The XML : eXtensible Markup Language - is a markup language and file format, designed to store and transport data, to be self-descriptive and both human- and machine-readable, and is a W3C Recommendation.
All XML elements can be accessed through the XML DOM.
The XML DOM is:
- a standard object model for XML
- a standard programming interface for XML
- platform- and language-independent
- a W3C standard
According to the XML DOM, everything in an XML document is a node:
- The entire document is a document node
- Every XML element is an element node
- The text in the XML elements are text nodes
- Every attribute is an attribute node
- Comments are comment nodes
Now let's switch to QGIS. Obviously, it comes with some embedded XML Python Packages e.g. xml, lxml, xmlrpc, and others (possible to see with help("modules xml")). However, QGIS uses the QtXml module to provide a C++ implementation of the DOM standard for XML.
The PyQt5.QtXml module contains two previously mentioned classes:
| class |
explanation |
QDomDocument |
Represents an XML document (a text file with a tree structure) |
QDomNode |
The base class for all the nodes in a DOM tree (a DOM model constructed as a tree of Objects) |
So, how to use the writeXml() method?
First of all, it requires a node i.e. QDomNode. Simply saying a spot, where to to insert the structured content of the QgsAttributeTableConfig.
Secondly if one decides to export that node into something like XML looking, one needs a certain approach. So, the QDomDocument class can be used. It has some methods. Another approach was shown by @KadirŞahbaz with the QTextStream class for reading and writing text.
References: