Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: get siblings

  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    get siblings

    Hi!
    I need some help trying to get siblings in an xml file, I have got the value of the element <name> and want to find the value of names siblings. The problem is that there are a lot of name elements, but since I have the specific value of name i Should be able to find its siblings, shouldn't I?

    example of the xml-file that I am parsing:
    Code:
    <Layer queryable="0" opaque="0" cascaded="0">
    <Name>na_drain_nam</Name>
    <Title>River Names</Title>
    <Abstract>Names of rivers in the North America region.</Abstract>
    <SRS>EPSG:4326</SRS>
    <LatLonBoundingBox minx="-180" miny="-4.94415" maxx="180" maxy="89.9992"/>
    <BoundingBox SRS="EPSG:4326" minx="-180" miny="-4.94415" maxx="180" maxy="89.9992"/>
    </Layer>
    −
    <Layer queryable="0" opaque="0" cascaded="0">
    <Name>na_division_nam</Name>
    <Title>Province, Territory, State Names</Title>
    −
    <Abstract>
    Province, territory, and state names in the North America region.
    </Abstract>
    <SRS>EPSG:4326</SRS>
    <LatLonBoundingBox minx="-180" miny="-4.94415" maxx="180" maxy="89.9992"/>
    <BoundingBox SRS="EPSG:4326" minx="-180" miny="-4.94415" maxx="180" maxy="89.9992"/>
    </Layer>
    How or what function in javascript can I use to get the values for the siblings?

    please help!
    /Paul
    Last edited by Kor; 03-17-2011 at 12:35 PM. Reason: wrap the code [code][/code]

  • #2
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Could be something like this:
    Code:
    var val='na_drain_nam';
    var names=document.getElementsByTagName('Name'), n, i=0, children, c, res=[], j;
    while(n=names[i++]){
    	if(n.textContent==val||n.text==val){
    		alert(n.nodeName)
    		children=n.parentNode.childNodes;
    		j=0;
    		while(c=children[j++]){
    			if(c!=n&&c.nodeType==1){
    				res[res.length]=c.textContent||c.text;
    			}
    		}
    		break
    	}
    }
    alert(res)
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks a lot! with some changes in your code I got it to work perfekt in my work, thank you!
    ps. United rules!


  •  

    Posting Permissions

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