3

I want to know how to read all the elements' names in the following xml file:

<fruits>
    <apple> ... </apple>
    <banana> ... </banana>
    <grapes> ... </grapes>
    <mango> ... </mango>
    <papaya> ... </papaya>
    <strawberry> ... </strawberry>
</fruits>

Here, the condition is that I am not sure which fruits are available (e.g. whether or not apple is present on that day). I know only the element <fruits> is available; child names are unknown and the number of children for <fruits> is also unknown.

How can I find the fruits available on that day using Xerces DOM parsing?

reuben
  • 3,360
  • 23
  • 28
Balamurugan
  • 2,259
  • 8
  • 33
  • 48

1 Answers1

1

You can use the DOMNodeIterator to iterate all elements in your DOMDocument and then use the DOMNode->getName() to get the name and check if that's what you need.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • 1
    DOMNode doesn't have getName() member function http://xerces.apache.org/xerces-c/apiDocs-3/classDOMNode.html – Chrys May 20 '11 at 09:24