2 Replies Latest reply on May 5, 2008 12:48 AM by MayLam18

    How to get the attribute values out?

    MayLam18 Level 1
      Hi everyone,

      <category name="Mens Clothing" id="0">
      <subcategory>Active/Baselayer Tops</subcategory>
      <subcategory>Active/Baselayer Bottoms</subcategory>

      <category name="Womens Clothing" id="1">

      How to get the attribute values out? For example "Mens Clothing" and "Womens Clothing".

      // the line below returns "Active/Baselayer Tops" and "Active/Baselayer Bottoms"
      var myXml:XML = new XML(event.result);

        • 1. Re: How to get the attribute values out?
          atta707 Level 2
          Here is attribute identifier operator from FB Help:

          @ attribute identifier Operator

          Usage myXML.@attributeName

          Identifies attributes of an XML or XMLList object. For example, myXML.@id identifies attributes named id for the myXML XML object. You can also use the following syntax to access attributes: myXML.attribute("id"), myXML["@id"], and myXML.@["id"]. The syntax myXML.@id is recommended. To return an XMLList object of all attribute names, use @*. To return an attribute with a name that matches an ActionScript reserved word, use the attribute() method instead of the @ operator.

          Operands attributeName:* — The name of the attribute.

          How to use examples
          The first example shows how to use the @ (at sign) operator to identify an attribute of an element:
          var myXML:XML =
          <item id = "42">
          <catalogName>Presta tube</catalogName>

          trace(myXML.@id); // 42The next example returns all attribute names:
          var xml:XML =<example id='123' color='blue'/>
          var xml2:XMLList = xml.@*;
          trace(xml2 is XMLList); // true
          trace(xml2.length()); // 2
          for (var i:int = 0; i < xml2.length(); i++)
          trace(typeof(xml2 )); // xml
          .nodeKind()); // attribute
          trace(xml2 .name()); // id and color
          } The next example returns an attribute with a name that matches a reserved word in ActionScript. You cannot use the syntax xml.@class (since class is a reserved word in ActionScript). You need to use the syntax xml.attribute("class"):
          var xml:XML = <example class='123'/>