XML Getting attributes of a specific value
I have an XML document in this format:
Code:
<h1 Name="foo">
<h2 Name="goo" h2ID="0">
...
</h2>
<h2 Name="hoo" h2ID="1">
...
</h2>
<h2 Name="joo" h2ID="2">
...
</h2>
</h1>
I want to create a function that lets the user input the h2ID value, and then return the h2 Name associated with that value. How would I go about doing that?
So far I have:
Code:
QString Program
::getH2Name(int h2ID
) {
if (child2.tagName() == "h2") {
return child2.attribute("Name");
}
}
This will only return the Name of the first h2 element: "goo". How do I get a specific h2 element using the h2ID? Thanks.
Re: XML Getting attributes of a specific value
you can use QDomElement::elementsByTagName() and iterate over the returned list, till you get your id or use XQuery (->QXmlQuery).