0

I hope my questions isn't too dumb :)

What I want to do is to automatically list all different tagnames and attributes from a given xml document; from the first item for example. So that I can choose which ones I want to parse.

Example, for this xml:

<productItem id="123456">
    <name>laptop</name>
    <trackingLinks>
        <trackingLink>
            <ppc>http://xxxxxxxxx</ppc>
        </trackingLink>
    </trackingLinks>
    <description>laptop computer</description>
</productItem>

I should get a list of all tagnames/attributes like:

productItem>id

name

trackingLinks>trackingLink>ppc

description

Any ideas?

Thanks

hakre
  • 193,403
  • 52
  • 435
  • 836
Jdiid
  • 45
  • 2
  • 5
  • You are looking for all nodes that have no more children. You then list all their ancestor element nodes. Probably this can be easily done with xpath? – hakre Aug 06 '12 at 23:31
  • I'm not sure how...will this work without having to specify any tagname? – Jdiid Aug 07 '12 at 13:50
  • Yes that is possible (see as well: [Debug a DOMDocument Object in PHP](http://stackoverflow.com/a/8631974/367456)), however your criteria contain some information that is not part of the XML. For example why isn't it `productItem>trackingLinks>trackingLink>ppc`? Someone could argue there must be `productItem` at first, but in your question it's not there. – hakre Aug 07 '12 at 13:59

0 Answers0