8 Replies Latest reply on Jan 6, 2009 7:53 AM by kglad

    Loading an xml file from an xml file

    mikeyjray
      I'm trying to load an xml file from an xml file, but I'm having problems. My first xml file is really simple - it only contains one attribute with the name of another xml file in it (eventually I will have multiple xml files in here and run a loop on them...this is why I want to load an xml file from an xml file).

      Currently, with the code below, I can get the main xml file to load ("main.xml"), but I cannot get the secondary xml files to load FROM the main.xml.

      I want to then take childNode values from the secondary xml file and use them within my .swf in text boxes and whatnot.

      Any guidance? I think I'm going wrong on the line where I'm saying "i.newxml.load(i.attributes.location);"

      - How can I get this to work?
        • 1. Re: Loading an xml file from an xml file
          johnypeter
          Hi There,

          why do you use i.newxml variable? Is there any reason on using that?
          cos, I guess you can create a new variable inside the loop. Just try it and let me know if it works..
          • 2. Re: Loading an xml file from an xml file
            kglad Adobe Community Professional & MVP
            your for-loop is incorrect and you shouldn't nest a named function - loadXML().

            use the trace() function to see what you're doing in your for-loop.
            • 3. Loading an xml file from an xml file
              mikeyjray Level 1
              johnypeter:
              I tried changing the code inside the loop to use just "newxml" instead of "i.newxml", and I declared with "var newxml = new XML();" - was this what you were thinking?

              kglad:
              The reason I tried to use the loadXML() function in the loop was so that for each node in my "main.xml" it would load the new xml file listed - this is a no-no? Do you have any ideas as to what I could do?

              For the for-loop, what should I change in it? I'm not great with loops so I tried to modify some code from another loop I found in another forum thread - not the right way to do it here?

              Also, what should I trace? The value of the _root.address, or i.attributes.location? I have created dynamic text boxes on my stage to see if the correct value from the xml file loads (ie. the name of the xml file within the xml file) and it does, but now I don't know how to put that information into ANOTHER loadXML() function and get the node information from it - does that make sense???

              Below are the examples of the xml files I am using. In the first one, main.xml, I will have a list of multiple xml files, each with the same nodes and elements as in the details.xml file (different values, of course).

              This is just to give you an example of what I'm trying to accomplish - pulling ALL the addresses and phone numbers from multiple xml files. I cannot manually collect this information, as it is dynamic, and will be updated in each individual details.xml. I was hoping to collect the information by simply adding to and updating ONE xml file - main.xml.

              Do you think this can be done? Am I going about it the wrong way? I'm quite limited in AS knowledge, which is why I'm piecing together code from other posts!
              • 5. Re: Loading an xml file from an xml file
                mikeyjray Level 1
                Well, that seems to be working - I added a couple extra xml files to the main.xml and it is loading the details from each file.

                Now, if I want to store the information for each address and phone number from each xml file, I would have to setup the function parseXML() to store the information into a variable - could I use something like below?

                I know my syntax sucks, but I'm learning!
                • 6. Re: Loading an xml file from an xml file
                  kglad Adobe Community Professional & MVP
                  not if count and _root.count are the same:

                  count is numeric variable. you can't assign address and phone properties to it.

                  try:

                  addressA = [];
                  phoneA = [];
                  function parseXML(){
                  addressA.push(this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue);
                  phoneA.push(this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue);
                  }
                  • 7. Re: Loading an xml file from an xml file
                    mikeyjray Level 1
                    Thanks for all the help kglad - you've really helped me move forward with this project!
                    • 8. Re: Loading an xml file from an xml file
                      kglad Adobe Community Professional & MVP
                      you're welcome.