7 Replies Latest reply on Jun 21, 2007 2:26 PM by Greg Dove

    XML Problem w/ AS 2

    za beezo
      Hey, I am wondering if you can combine XML attribute tags w/ the simple <> tags in one doc.... I am using this XML:
      I am very sure my AS is correct- it's below the XML- included just in case... if not the tag style combo (for lack of a better name), what's wrong w/ the XML???

      <?xml version="1.0" encoding="UTF-8"?>
      <image title="Megabooth, Moreys Piers, Wildwood NJ" thumb ="assets/playTab/mb_tab.jpg" project = "megaBooth"/>
      <image title="Mariners Pier, Wildwood NJ" thumb ="assets/playTab/mp_tab.jpg" project = "marinersPier"/>
      <image title="Ocean Oasis Waterpark, North Wildwood, NJ" thumb ="assets/playTab/oa_tab.jpg" project = "pennLanding"/>
      <image title= "Penns Landing Redevelopment Project, Philadelphia, PA" thumb ="assets/playTab/pl_tab.jpg"/>
      <image title="Surfshop, Moreys Piers, Wildwood NJ" thumb ="assets/playTab/ss_tab.jpg" project = "surfShop"/>
      <image title="USA International Raceway Project, Shawano, WI" thumb ="assets/playTab/wi_tab.jpg" project = "usa"/>
      <image title="addTest1" thumb ="assets/playTab/test1.jpg" project = "test1"/>
      <image title="addTest2" thumb ="assets/playTab/test2.jpg" project = "test2"/>
      <image> "assets/play/random/mp003.jpg" </image>
      <image> "assets/play/random/oa003.jpg"</image>
      <image> "assets/play/random/pl004.jpg" </image>
      <image> "assets/play/random/wi001.jpg" </image>
      <image title = "assets/play/megaBooth/mb001.jpg" thumb ="assets/play/megaBooth/thumbs/mb001.jpg"/>
      <image title = "assets/play/megaBooth/mb002.jpg" thumb ="assets/play/megaBooth/thumbs/mb002.jpg"/>
      <image title = "assets/play/megaBooth/mb003.jpg" thumb ="assets/megaBooth/thumbs/mb003.jpg"/>

      //as below:

      import mx.xpath.XPathAPI;

      var xLoadRandom:XML = new XML();
      xLoadRandom.ignoreWhite = true;
      xLoadRandom.onLoad = function(success:Boolean) {
      if (success) {
      var titleArray:Array = XPathAPI.selectNodeList(this.firstChild, "/playSection/playMenu/randomImage");
      for (var i:Number = 0; i < titleArray.length; i++) {
      trace(titleArray .firstChild.nodeValue);
      } else {
      trace("XML loading failed !!!");
        • 1. Re: XML Problem w/ AS 2
          Rothrock Level 5
          Sorry, I don't understand what you mean at all. Is there something wrong with this? If so what?
          • 2. Re: XML Problem w/ AS 2
            za beezo Level 1
            Yeah, I don't know either but it doesn't work! I thought it was the XML tags using attributes w/ reg. tags. Thanks for taking a look anyway!
            • 3. Re: XML Problem w/ AS 2
              za beezo Level 1
              I have a theory as to why this doesn't work... (still cannot get it to work). I think it is in the way the Flash sorts the nextSibling after a firstChilds, childNodes...Ok??? In other words:

              I have found other examples on the web of people have problems w/ this when the XML has this format as mine does:

              <subOne> aasdasdasdasd<subOne>
              <subTwo> ggthrreeee</subTwo>

              It this poorly formed in some way???? My example does have attributes, but should this matter? I did try adding [ ] for the attricbutes as well.


              • 4. Re: XML Problem w/ AS 2
                Rothrock Level 5
                Not sure. And no the problem isn't attributes. The whole thing would be pretty useless if you couldn't use attributes.

                You do know that the whole thing is the firstChild, right? So to get inside you will need a firstChild of the firstChild. I think?
                • 5. Re: XML Problem w/ AS 2
                  hciguy Level 1
                  You do know that <tag name="dog" /> is different than <tag>Dog</tag> right? I don't rememer in AS 2.0, but in AS 3.0 in the second tag Dog is a child of tag whereas in the first dog is an attribute of tag. It requires a different way to get to Dog in each case. Don't know if it pertains but just sharing.I've never used XPath so I can't say for sure...don't know how it works.

                  And in this structure:


                  Subtag is a child of tag1 and Dog, as far as I know, is considered a child of Subtag.

                  And no, it is fine to have attributes of a tag.
                  • 6. Re: XML Problem w/ AS 2
                    hciguy Level 1
                    A theory.

                    In your AS code you havethis in your XPath call:


                    That is fine and dandy except, randomImage isn't a child of PlayMenu. It is actually a child of playSection, judging by the XML you gave. So, it seems to me who has never used XPath, that you'd need to do "/playSection/randomImage" to get to randomImage. There is no XML path in your document that corresponds to "/playSection/playMenu/randomImage." PlaySection has three children: playMenu, randomImage, megaBooth.

                    • 7. XML Problem w/ AS 2
                      Greg Dove Level 4
                      You can use either selectSingleNode to get to randomImage or selectNodeList to get to the image nodes.