PDA

View Full Version : XML text



abrou
27th February 2008, 00:18
Hello, simple question, but if I am using QDom, and read an .XML file, if there is a line like:


<title>Hello World</title>

how do I change it to something like:


<title>Something New</title>

It should be simple, but I am having trouble figuring it out. I only want to change the text, nothing else, not the position in the QDomDocument. Does this make sense? (By the way, I am reading an .XML created by excel, and writing a program to insert data into the "excel" sheet)

Thanks!

Anna B

wysota
27th February 2008, 09:05
Create a QDomText object using QDomDocument::createTextNode and replace the original text node with yours.

abrou
27th February 2008, 18:18
Hello, thanks for your reply... I've been playing with it, and since I am also new to XML, I think I don't understand what it going on.


QDomText newNode = doc.createTextNode("New Text");
t = n.parentNode();
QDomNode oldNode = t.replaceChild(newNode, n);

What happens is that it replaces the node with only
"New Text", which can be seen below.


<Row ss:Height="13.5" ss:AutoFitHeight="0">
- <Cell ss:StyleID="s38">
<Data ss:Type="String">Number of Quadrants</Data>
</Cell>
New Text //See? Not really a node, I don't think.
- <Cell ss:StyleID="s40">
<Data ss:Type="Number">14</Data>
</Cell>
</Row>

So, the replace works, my problem is that my node looks only like text..... as I said, I am new to XML...thanks!

How can I make a node that looks like this:

<Data ss:Type="String">New Text</Data>

abrou
27th February 2008, 18:46
I figure it out, I missunderstood what a TextNode should look like, I always pictures it as part of a Node. I've fixed it, by refering to the second child of the node I originally replaced. FYI, I also had to change the attribute to read "String" instead of "Number" because excel didn't want to open it otherwise.

Thanks!