I am new to flex development. I am trying to develop a web based application. somehow I feel comfortable. I have some queries related to xml documents.
In my webservice I perform some database operation and return some xml data in XmlDocument Object format.
I tried to parse it using below function
public function objectToXML1(obj:Object):XML {
var qName:QName = new QName("DATA");
var xmlDocument:XMLDocument = new XMLDocument();
var simpleXMLEncoder:SimpleXMLEncoder = new SimpleXMLEncoder(xmlDocument);
var xmlNode:XMLNode = simpleXMLEncoder.encodeValue(obj, qName, xmlDocument);
var xml:XML = new XML(xmlDocument.toString());
return xml;
}
but I don’t know how to pull data from this XML
XML FORMAT
<REQUEST>
<STATUS>SUCCESS</STATUS>
<MESSAGE>BP Retrive </MESSAGE>
<DATA>
<BOM>
<BO>
<BusinessPartners>
<row>
<CardCode/>
<CardName/>
<Phone1/>
<Phone2/>
<Cellular/>
<EmailAddress/>
</row>
</BusinessPartners>
</BO>
</BOM>
</DATA>
</REQUEST>
If you have a predefined structure of the XML, you could use FlexXB to create an ActionScript Object of the XML. It is pretty easy, you create an ActionScript Object which looks exactly like the XML (that means it need to have the same properties) and you annotate these properties. So FlexXB will read the XML and create an ActionScript Object form it.
If you don’t want to use the framework, you can do it by hand too. To read attributes, use
xmlElement.@attributeNamefor getting the name of an object use e.g.xmlElement.name().localName. There are some functions, but since the autocompletion doesn’t work for XML elements it is a little hard to find the right functions. Here is an article by Adobe which explains how to work with XML. Basicall you can just use the node names as property names. In your case you could writexmlElement.Phone1and so on.Hope it helps 🙂