2013年10月8日星期二

[Android] Qt generate the XML file node attribute order disorder problems

Achieved with QDomDocument generate an XML file ,
one of the nodes in the following order generate attributes:
id, name, desc, width, height
but the resulting file format is like this :
< / pNode>
That node attribute order is not in accordance with the code stored in the order in writing , may I ask a great God, how is this going ? How to solve ?

------ Solution ------------------------------------ --------
xml sort of attribute attribute is irrelevant , and how rows are the same, for the resolution did yo effect .
it is generally dom processing libraries are random or sorted according to their pre-determined .

sort does not affect the analysis of the sort , I do not know for what you ask for sorting ? Good-looking ?
So if you want to order special needs , it becomes the Attribute node.
------ eference --------------------------------------- < br> about the code ? Tie bar code
------ eference ------------------------------------- -
code is shown below :
void Q_CustomClass :: saveToXml (QDomDocument & doc, QDomElement root)
{
QString sValue;
QDomElement element;
element = doc.createElement ("picnode");

sValue = m_stAttribute.picName;
QDomAttr Attr = doc.createAttribute (tr ("name"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = m_stAttribute.picDesc;
Attr = doc.createAttribute (tr ("desc"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.picX);
Attr = doc.createAttribute (tr ("x"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.picY);
Attr = doc.createAttribute (tr ("y"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.disWidth);
Attr = doc.createAttribute (tr ("disWidth"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.disHeight);
Attr = doc.createAttribute (tr ("disHeight"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.picWidth);
Attr = doc.createAttribute (tr ("picWidth"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.picHeight);
Attr = doc.createAttribute (tr ("picHeight"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.picDisStyle);
Attr = doc.createAttribute (tr ("disStyle"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

sValue = QString :: number (m_stAttribute.picBorderStyle);
Attr = doc.createAttribute (tr ("borderStyle"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

if (true == m_stAttribute.fullScreen)
{
sValue = "true";
}
else
{
sValue = "false";
}
Attr = doc.createAttribute (tr ("fullScreen"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

if (true == m_stAttribute.ifScroll)
{
sValue = "true";
}
else
{
sValue = "false";
}
Attr = doc.createAttribute (tr ("ifScroll"));
Attr.setValue (sValue);
element.setAttributeNode (Attr);

root.appendChild (element);

}

------ eference ------------------------------------ ---
generated stylistic node as follows:

------ eference ------------------------------------ ---
is this:

------ eference ------------------------------- --------
Thank you for your answer !
course in accordance with the attribute name can be resolved , but now there is such a demand , according to the order of the output attribute names and values ​​, without regard to the attribute name is.
It seems only a switch node .
------ eference --------------------------------------- < br> I also encountered a similar problem, replace attribute values ​​and regenerate new xml , found all tag attributes in the order reversed . . .
I do not know how to solve ! ?
------ eference --------------------------------------- < br> landlord, I have encountered this problem , in the end how to solve ah, the more points you can say ?
------ eference --------------------------------------- < br> landlord how to solve it

没有评论:

发表评论