dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: how to get the length of an XML file?

  1. #1
    Member
    Join Date
    Mar 2005
    Posts
    47

    how to get the length of an XML file?

    Just wondering how to return the length of an XML file. Say I have 5 sets of cities that include names & images. I tried length() but it always returns 1. I'm now assuming this isn't like an array.

  2. #2
    Member
    Join Date
    Mar 2005
    Posts
    47
    I guess I should rephrase this. I just need to find out the number of sets that are in the xml file.

  3. #3
    Junior Member
    Join Date
    Apr 2002
    Location
    Memphis
    Posts
    27
    Using the following as sample XML data:
    Code:
    <main>
    	<sub1>
    		<item></item>
    		<item></item>
    		<item></item>
    	</sub1>
    	<sub2>
    		<item></item>
    		<item></item>
    	</sub2>
    </main>
    You would load the file XML file into a variable (let's use myXML) typed as XML.
    To find the number of nodes directly under the "main" node you would use:
    Code:
    myXML.child("*").length();
    This is referring to "sub1" and "sub2." Because they have different names, you would use the asterick to give all nodes under "main." You could also put the name of the nodes you want to count in place of the asterick.

    To find the nuber of nodes directly under "sub1", you would use either:
    Code:
    myXML.sub1.child("item").length();
    OR (the more direct way)
    Code:
    myXML.sub1.item.length();
    Since you know the names of the nodes, you can call them directly. For your homework, what is the code to find the number of child nodes under sub2? Hope this helps.

  4. #4
    Member
    Join Date
    Mar 2005
    Posts
    47
    Thanks ddane! I just found this as you posted & it worked also...gracias!

    // I already loaded the data before this part I just needed to use a variable to determine the loop length

    var xmlSetLength:Number = xmlLoader.children().length();
    trace(xmlSetLength + " is the length");

    In answer to your quiz I would have to guess that ....myXML.sub2.item.length() would return the # or items for sub2. Is that correct?


    I would mark this thread resolved but I'm not sure how :-)

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