Reputation: 456
I'm trying to parse an Xml file using QDomDocument.
I've got the root element. Now I need to find and extract specfic nodes
under the root element but only at the first level of hierarchy.
I tried to use:
QDomElement root = doc.documentElement();
QDomNodeList nodeList = root.elementsByTagName("apple");
But this returns me a nodeList which contains the nodes with tag Name "apple"
in all levels of hierarchy. But I need only a first level search.
Could someone please help me out.
Thanks
Upvotes: 1
Views: 2371
Reputation: 5718
There's no method to do exactly what you want but it's easy to achieve by iterating over the children with something like:
QList<QDomElement> elements;
QDomElement child = root.firstChildElement("apple");
while(!child.isNull()) {
elements.append( child );
child = child.nextSiblingElement("apple");
}
Upvotes: 5