PDA

View Full Version : QStringList withing QDomText



NoRulez
5th November 2008, 08:00
I want to append a QDomText which is a QStringList to an existing QDomElement. Currently I use the following:


QDomText text = doc.createTextNode(strList.join("\n"));
element.appendChild(text);
element.setAttribute("size", strList.size());


So for this example the output would be:


<node1>
<data>
<element size="4" >Article1
Article2
Article3
Article4</element>
</data>
</node1>


I want to make it better readable, so my question is how can i use these functions to produce:


<node1>
<data>
<element size="4" >
Article1
Article2
Article3
Article4
</element>
</data>
</node1>


Is there a beautifier within the QtXml which i couldn't found? I seem to remember that xerces will do so.
How can i do so with standard Qt tools?

Regards

aamer4yu
5th November 2008, 09:15
what are you using to display the xml data ?? My guess is QListWidget..
QTextEdit is good for displaying xml.
Hint :

QString xmlString;
QTextStream stream(&xmlString);
myRootElement.save(stream,4);

QTextEdit::setPlainText(xmlString);

NoRulez
5th November 2008, 11:05
what are you using to display the xml data ?? My guess is QListWidget..
QTextEdit is good for displaying xml.
Hint :

QString xmlString;
QTextStream stream(&xmlString);
myRootElement.save(stream,4);

QTextEdit::setPlainText(xmlString);



This code snippet doesn't work. The only thing what the snippet does is adding 4 spaces instead of 1 for every node.

I want to write the QStringList within QDomText so that when a user opens the xml file with his prefered editor he knows that this is a list of values.

Once more:
Currently this is written:


<element size="4" >Article1
Article2
Article3
Article4</element>


And this should be, but the question is how?


<element size="4" >
Article1
Article2
Article3
Article4
</element>


Regards

NoRulez
11th November 2008, 11:01
*Push*

Does nobody know a way on how to do this?

Regards

aamer4yu
12th November 2008, 07:18
hmm,,, seems its more of spacing prob than i thought...
first u are using strList.join("\n"); u also need to prepend and append '\n' to it, right ?

still u wont get the efftect...bec after new line, you dont know how many spaces to leave..
do thats another function to calculate space for current node, relative to the root node.

hope u get the idea now..

anyhow I feel ther might better way to do what u are doing... cud u show some more code or snapshots ??

NoRulez
13th November 2008, 10:13
I saw this from various other xml files, so i can do the following:


<element size="4" >
<string>Article1</string>
<string>Article2</string>
<string>Article3</string>
<string>Article4</string>
</element>

but i think with the other way, a user can faster recognition that the content is a list.
How can i get the space for a current node?

Regards