2 Replies Latest reply on Aug 11, 2008 9:00 AM by Varangian

    xml contains method

    Varangian Level 1
      I have this xml in my flex application.

      <mx:XML id="myMenu">
      <root>
      <menuitem label="Click here" data="s0" />
      <menuitem label="Take trip" data="s1" />
      </root>
      </mx:XML>


      in a private method I'm checking if an xml node already exists using the contains method. Basically I click on the canvas and add menuitem to the XML list (which is being added). However on the second click it is added again. This is because the contains method is not doing it's job.
      The !items.contains(xmlitem) always returns false even though when I debbugged the and watched the XML list there is the actual xml node <menuitem label="PUFTA" data="s3" />
      .... please any help on why is this?
      thanks
      below is the code


      menume = Menu.createMenu(mycanvas,myMenu,false);
      menume.labelField="@label";
      menume.dataTipField = "@data";

      var items:XML = menume.dataProvider[0] as XML;
      var xmlitem:XML = <menuitem label="PUFTA" data="s3" />;
      if (!items.contains(xmlitem))
      {
      items.appendChild(xmlitem);
      }

      menume.dataProvider = items;

        • 1. Re: xml contains method
          Level 7

          "Varangian" <webforumsuser@macromedia.com> wrote in message
          news:g7n7th$s3k$1@forums.macromedia.com...
          >I have this xml in my flex application
          >
          > <mx:XML id="myMenu">
          > <root>
          > <menuitem label="Click here" data="s0" />
          > <menuitem label="Take trip" data="s1" />
          > </root>
          > </mx:XML>
          >
          >
          > in a private method I'm checking if an xml node already exists using the
          > contains method. Basically I click on the canvas and add menuitem to the
          > XML
          > list (which is being added). However on the second click it is added
          > again.
          > This is because the contains method is not doing it's job.
          > The !items.contains(xmlitem) always returns false even though when I
          > debbugged
          > the and watched the XML list there is the actual xml node <menuitem
          > label="PUFTA" data="s3" />
          > .... please any help on why is this?
          > thanks
          > below is the code
          >
          >
          > menume =
          > Menu.createMenu(mycanvas,myMenu,false);
          > menume.labelField="@label";
          > menume.dataTipField = "@data";
          >
          > var items:XML = menume.dataProvider[0] as XML;
          > var xmlitem:XML = <menuitem label="PUFTA" data="s3" />;
          > if (!items.contains(xmlitem))
          > {
          > items.appendChild(xmlitem);
          > }
          >
          > menume.dataProvider = items;

          This returns true when I try it:

          var myXML:XML = <root>

          <menuitem label="Click here" data="s0" />

          <menuitem label="Take trip" data="s1" />

          <menuitem label="PUFTA" data="s3" />

          </root>

          var myXMLList:XMLList = myXML.children();

          var node:XML= <menuitem label="PUFTA" data="s3" />;

          trace(myXMLList.contains(node));

          You may also want to try:

          myXMLList.(attribute('label')=='PUFTA').length()>0 &&
          myXMLList.(attribute('data')=='s3').length()>0



          HTH;



          Amy


          • 2. Re: xml contains method
            Varangian Level 1
            dude it works... lol .... the children was missing.