How to parse/write the attributes of a tag using QDomNode?
-
This is my XML
<FileName>
<File Width="" Name="../SupportFiles/TestVectors/10b- Cityscape [Landscape] 1 Min_1080p MP4.mp4" Height="" Format="" FrameRate=""/>
</FileName>I should read only Name attribute of the FileName tag.How do I do this using QDom?How to write attributes using QDom?
-
@kishore_hemmady
doc.qt.io/qt-5/qdomattr.html contains all the details, including examples of reading & writing. -
hi @JonB
how can i Write the above xml using XMLStreamWritter class. -
@kishore_hemmady
For writing an attribute, if that's what you mean:QXmlStreamWriter w = // ... QDomElement e = //... //... QDomAttr a = e.attributeNode("Name"); // ... w.writeAttribute(e.name(), e.value());
But now you're asking about
QXmlStreamWriter
, which you weren't before. I don't know why you're mixing this withQDom
. Normally, you read everything withQDom
, maybe make some changes, and then write everything back withQDom
. Take a look at e.g. http://www.informit.com/articles/article.aspx?p=1405553&seqNum=4:Using QXmlStreamWriter to write XML is the easiest and safest approach, but if we already have the XML in a DOM tree, we can simply ask the tree to output the relevant XML by calling save() on the QDomDocument object.