SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Retrieving Attribute Data from Parent Node

    my xml file is basically laid out like this...
    Code:
    <mystuff name="test">
        <box boxname="mybox1" version="2" weight="2">
            <bag bagname="mybag1" weight="5">
                <bag bagname="mybag1.1" weight="4"></bag>
                <bag bagname="mybag1.2" weight="3"></bag>
            </bag>
        </box>
        <box boxname="mybox2" version="2" weight="4"></box>
    </mystuff>
    i'm using an xpath to retrieve all elements with a weight of "4" that looks like this...
    Code:
    //box[@weight='4'] | //bag[@weight='4'
    and this gets the elements perfect. no problems.

    as i loop through those elements, i'd like to also retrieve the parent names (if any) of those elements. how can i do this?

  2. #2
    SitePoint Evangelist NokX's Avatar
    Join Date
    Feb 2003
    Location
    Knoxville, TN
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nevermind...got it...

    mynode.parentNode.getAttribute("att_name");

    easy enough :P


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •