how can i count the parents (or entries) in an xml file?
The XML below should show that I don’t know the entries in there so I need to count the tags to use them in a loop and save them in a QVector. From there on I could search the xml for a (now known) tag and get the childs and attributes (but thats another thing).
First step is to count the parents.
If anyone has a better solution then please let me know!
<?xml version="1.0" encoding="UTF-8" ?>
<Content>
<person1>
<firstname>John</firstname>
<surname>Doe</surname>
<email>john.doe@example.com</email>
<website>http://en.wikipedia.org/wiki/John_Doe</website>
</person1>
<person2>
<various>Some Text here.</various
<website>http://www.google.com</website>
</person2>
<person3>
<firstname>Jane</firstname>
<surname>Doe</surname>
<email>jane.doe@example.com</email>
<website>http://en.wikipedia.org/wiki/John_Doe</website>
</person3>
<person4>
<firstname>Matti</firstname>
<surname>Meikäläinen</surname>
<email>matti.meikalainen@example.com</email>
<website>http://fi.wikipedia.org/wiki/Matti_Meikäläinen</website>
</person4>
<person5 Attribute="Test">
</person5>
</Content>
I’ve tried to open the file and read it line per line while search for an RegExp (with less success) like one would do it in bash. But there must be a better solution with the XML functions from Qt4. Any suggestios?
I’ve found a solution. It’s not very nice but it works:
This one counts all Elements (k) and all Childs (i) and substracts Childs from Elements. So i get the amount of entries (persons in this case). If someone has a better solution then please post it.