How to get values of child nodes with QDomDocument?
12,427
So apparently the text inside a node is a node itself, too. This is how it works:
QString argument(int index)
{
QDomNode arg = xml->firstChild().namedItem("arguments");
return arg.childNodes().at(index).firstChild().nodeValue();
}
Comments
-
Tamás Szelei almost 2 years
A recieve a string like this:
<invoke name="CanClose" returntype="xml"> <arguments> <string># 998.40</string> <number>49920</number> </arguments> </invoke>
I'd like to use
QDomDocument
to get the values of arguments' child nodes by their index (I would like to extract the strings "# 998.40" and "49920" in the example).This is what I tried:
QString argument(int index) { QDomNode arg = xml->elementsByTagName("arguments").at(index); return arg.nodeValue(); }
But even
arg
was empty. What am I doing wrong here?Thanks in advance.