A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: This should be simple! Nested XML.

  1. #1
    Senior Member flipsideguy's Avatar
    Join Date
    Dec 2000
    Location
    Sweden
    Posts
    834

    This should be simple! Nested XML.

    My XML structure:
    Code:
    <search>
    <set name="one">
    <image client="google" />
    <image client="msn" />
    <image client="yahoo" />
    </set>
    <set name="two">
    <image client="lycos" />
    <image client="altavista" />
    <image client="ask" />
    </set>
    </search>
    1. How do I get all the values from set "one"?
    2. How do I get all the values from set "two"?

    This is getting very messy. I have spent hours. I can get the values of all sets (parents) but I can't get the values of the children inside a specific set.

    All help is much appreciated. I have searched high and dry.

    Thanks!!!!!!!!

    Flipsideguy
    Flipsideguy

  2. #2
    Senior Member flipsideguy's Avatar
    Join Date
    Dec 2000
    Location
    Sweden
    Posts
    834
    So I have been playing with hit, and finding good replies here on FK that's helped me a bit.

    How do I only get the attributes from one <search></search> at a time?

    Currently the trace shows node attributes (client) from all available <image client=""/>

    I would greatly appreciate your help. Been at it for days without a solution.

    Here's what I have now:

    XML
    Code:
    <search>
    <set name="one">
    <image client="google" />
    <image client="msn" />
    <image client="yahoo" />
    </set>
    </search>
    
    <search>
    <set name="two">
    <image client="lycos" />
    <image client="altavista" />
    <image client="ask" />
    </set>
    </search>

    AS
    Code:
    myXML = new XML();
    myXML.ignoreWhite = true;
    myXML.onLoad = function() {
    	xmlParse(this);
    };
    myXML.load("searchengines.xml");
    
    xmlParse = function (xmlObj) {
    	aNode = xmlObj.childNodes;
    	len1 = aNode.length;
    	for (var i = 0; i<len1; i++) {
    		len2 = aNode[i].firstChild.childNodes.length;
    		for (var j = 0; j<len2; j++) {
    			trace(aNode[i].firstChild.childNodes[j].attributes.client);
    		}
    	}
    };
    Flipsideguy

  3. #3
    Senior Member flipsideguy's Avatar
    Join Date
    Dec 2000
    Location
    Sweden
    Posts
    834

    I'm such an XML Noob!

    So I managed to solve it myself

    I had the two for loops nested, which returns all nodes and attributes. But to only access a specific set you have to separate the two for loops. I'm posting it here just in case someone else has the same problem. Sharing is caring.
    Code:
    myXML = new XML();
    myXML.ignoreWhite = true;
    myXML.onLoad = function() {
    	xmlParse(this);
    };
    myXML.load("searchengines.xml");
    
    xmlParse = function (xmlObj) {
    	aNode = xmlObj.childNodes;
    	len1 = aNode.length;
    	for (var i = 0; i<len1; i++) {
    		len2 = aNode[i].firstChild.childNodes.length;
    	}
    	for (var j = 0; j<len2; j++) {
    		trace(aNode[0].firstChild.childNodes[j].attributes.client);
    	}
    
    };
    This should now return all values / attributes of the first set.
    Flipsideguy

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center