Question about php domelement objects

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Thorogood

    Question about php domelement objects


    Hello all. When I do a print_r of a domelement object I get something like this:

    domelement Object
    (
    [type] => 1
    [tagname] => category
    [0] => 6
    [1] => 1007543104
    )

    What are those "0" and "1" internal variables? I can not seem to find any description
    of them anywhere. What do they represent? The "0" one seems to stay constant with a
    constant xml source. But the "1" one is always different though still unique. Are
    these variables a php thing only? Or part of the dom specification that I missed?

    Also how do I access them? I can do a "$node->tagname" or "$node->type" just fine to
    get access to those internal object variables. But php does not like "$node->0" at all.
    What's the problem? Some kinda of variable scoping or something?

    Lastly, I don't suppose there is any way to search by these "0" variables with an
    xpath_eval statement?

    The problem is this: I will be receiving an xml file with all these nested "category"
    elements. They only have "name" attributes, which unfortunately, I can not be guaranteed
    will be unique. But I still need some unique way to identify them. Short of adding
    attributes to each "category" element, I was hoping to use this "0" internal object
    variable, or perhaps, the position() function from xpath. But I have no idea how to
    determine an elements position when all I have is the domelement object.

    Thanks for any help!

  • Janwillem Borleffs

    #2
    Re: Question about php domelement objects

    George Thorogood wrote:[color=blue]
    > Hello all. When I do a print_r of a domelement object I get
    > something like this:
    >
    > domelement Object
    > (
    > [type] => 1
    > [tagname] => category
    > [0] => 6
    > [1] => 1007543104
    > )
    >
    > What are those "0" and "1" internal variables? I[/color]

    I was unable to reproduce this output, can you post a snippet which results
    in this?
    [color=blue]
    > But I have
    > no idea how to determine an elements position when all I have is the
    > domelement object.
    >[/color]

    With an XPath expression, you can group category elements with equal values
    for the name attributes:

    //category[@name='value']

    If you want the first matching node, just do:

    //category[@name='value'][1]


    JW



    Comment

    Working...