Thursday, January 26, 2012

E4X - Traversing XML With Namespace In ActionScript

Take this example:

var xml:XML =
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="note">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="to" type="xs:string"/>
      <xs:element name="from" type="xs:string"/>
      <xs:element name="heading" type="xs:string"/>
      <xs:element name="body" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

</xs:schema>;

To get the sequence XML, we first define the namespace and use it as follows:

var xs:Namespace = new Namespace("xs", "http://www.w3.org/2001/XMLSchema");

var sequenceXML:XMLList = xml.xs::element.xs::complexType.xs::sequence;


No comments:

Post a Comment