Hi all,
I want to read a xml file, parse it, modify some values and finally generate a file with the information read. Is it possible without write the xml in the code (hardcoded)?
Best regards.
Printable View
Hi all,
I want to read a xml file, parse it, modify some values and finally generate a file with the information read. Is it possible without write the xml in the code (hardcoded)?
Best regards.
With QDomDocument it is needed write the nodes, e. g.:
Code:
doc.appendChild(root); root.appendChild(tag); tag.appendChild(t);
I want to generate a XML from the information of XML document read.
I'm sorry I don't understand what that means. How do you want to modify XML nodes without accessing the nodes?
QDomDocument::setContent().
Cheers,
_
I'm sorry. I will try to explain it better.
I want this:
1.- I parse a XML document. For example:
Code:
<?xml version="1.0" encoding="UTF-8"?> <information> <node1>data1<node1> <node2>data2<node2> </information>
The node1 and node2 values are put into QLineEdit's.
2.- I update the information from GUI. data1 --> "myValue1" and data2 --> "myValue2".
3.- I generate a XML with the new values. <-- How can I generate a new XML? I have a method with the XML hardcoded to generate the file. This is a problem if the XML changes or if the XML is very big.
Code:
<?xml version="1.0" encoding="UTF-8"?> <information> <node1>myValue1<node1> <node2>myValue2<node2> </information>
Now my code is like this:
What exactly is the problem?
If your XML file contains more information that the two strings, and you want to update those strings and leave the rest of the document unchanged, then use QDomDocument as others have already explained.
If you only care about those two strings and just want to write a new XML file with only those two strings (thus losing any existing additional content), then you can simply write it with QXmlStreamWriter. It improves over your current solution because it properly escapes the two strings.
QDomDocument can both read existing and create new documents. So just read the existing xml document, modify it and save it again. I don't really see the problem.
I've used QDomDocument. Thank you.
Regards.