I am trying to parse some XML in AS3 that I recieve thru a WebService call to C#. C# is serializing using a DataContract so the namespace is non standard.
Here is what the xml looks like:
<User xmlns="http://schemas.datacontract.org/2004/07/UserDatabaseManipulation.POCO" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Email>
<EmailString>
[email protected]
</EmailString>
</Email>
<Password>
<PasswordPlainText>
password
</PasswordPlainText>
</Password>
<ReferralDetails>
<ReferralEmail/>
<ServiceCreatedAt>
google
</ServiceCreatedAt>
</ReferralDetails>
<UserDetails>
<Address>
Penn Ave
</Address>
<City>
Washington DC
</City>
<Country>
USA
</Country>
<FirstName>
Bill
</FirstName>
<LastName>
Clinton
</LastName>
<State>
AK
</State>
<Zip>
11111
</Zip>
</UserDetails>
</User>
So as you can see from that I have a User which consists of Email, Password, Referral Details, and UserDetails.
Here is where I parse it and the problem:
private function onResult(event:ResultEvent):void
{
var n:Namespace = new Namespace("http://schemas.datacontract.org/2004/07/UserDatabaseManipulation.POCO");
use namespace n;
//This WORKS! ResultXml is loaded with the correct looking XML.
var resultXml:XML = new XML(event.result);
//This doesnt work! I just end up with an empty XMLList.
var email:Object = resultXml.Email;
...
Here's a screen shot in debug view (copy link and re-view to see it bigger):
Without e4x I can get it to work like this but it is really clunky:
var resultXml:XML = new XML(event.result); // the whole block of XML
var email:XML = resultXml.children()[0]; // the email object XML
var emailText:XML = email.children()[0]; // the email text
var emailActualXml:XML = emailText.children()[0]; // the email string in xml
var emailString:String = emailActualXml.toString();
Screenshot:
HERES THE SOLUTION
var xmlNamespace:Namespace = new Namespace( // namespace in here );
var resultXml:XML = new XML(event.result);
var email:XMLList = resultXml.xmlNamespace::Email;
var emailString:Object = email.xmlNamespace::EmailString.text().toString();