Re: XML Dom parsing function
add the code:
Code:
node = node.firstChild();
right after line: 22. This will support early attributing. I.E. Family/@Foley/Foley[0]/@First if your XML looks like this:
Code:
<xml>
<Family Name="Foley">
<Foley First="Justin">Justin</Foley>
<Foley First="Ashley">asdf</Foley>
<Foley>Gavin</Foley>
</Family>
</xml>
Re: XML Dom parsing function
Did you notice QXmlQuery? It makes exactly what your custom function does...
Re: XML Dom parsing function
No, I did not. Thank you for enlightening me.
UPDATED CODE:
Code:
{
doc.setContent(xmlFile);
node = docElement.firstChild();
pathFiles = path.split("/");
for(int i = 0; i < pathFiles.length(); i++)
{
if(curpath.startsWith('@'))
{
curpath = curpath.remove('@');
QString rightNode
= pathFiles
[i
-1];
if(rightNode.contains('['))
{
rightNode = rightNodeChildren[0];
}
if(node.nodeName() != rightNode)
node = node.parentNode();
return node.attributes().namedItem(curpath).nodeValue();
}
else
{
if(curpath.contains('['))
{
subIndex = subIndex.remove(']');
for(unsigned int x = 0; x < node.parentNode().childNodes().length(); x++)
{
if(node.nodeName() == subNode)
{
if(pathFiles[i] == pathFiles.back())
{
if(node.parentNode().childNodes().item(subIndex.toInt()).nodeName() == subNode)
// return node.parentNode().childNodes().item(subIndex.toInt()).nodeName();
returnString = node.parentNode().childNodes().item(subIndex.toInt()).firstChild().nodeValue();
break;
}
else
node = node.parentNode().childNodes().item(subIndex.toInt());
}
}
if(node.hasChildNodes())
node = node.firstChild();
}
else
{
for(unsigned int x = 0; x < node.parentNode().childNodes().length(); x++)
{
if(node.nodeName() == pathFiles[i])
{
if(pathFiles[i] == pathFiles.back())
{
if(node.nodeName() == pathFiles[i])
returnString = node.firstChild().nodeValue();
break;
}
}
else
node = node.nextSibling();
}
if(node.hasChildNodes())
node = node.firstChild();
}
}
}
return returnString;
}