7

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):

alt text

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:

alt text

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();

3 Answers 3

5

You must use the fully qualified name (including the namespace) when there are namespaces involved.

var n:Namespace = new Namespace("http://schemas.datacontract.org/2004/07/UserDatabaseManipulation.POCO");
var resultXml:XML = new XML(event.result);  
var email:Object = resultXml.n::Email;

Or use the default xml namespace directive

default xml namespace = new Namespace("http://schemas.datacontract.org/2004/07/UserDatabaseManipulation.POCO");

var resultXml:XML = new XML(event.result);  
var email:Object = resultXml.Email;
Sign up to request clarification or add additional context in comments.

Comments

1
    <?xml version="1.0" encoding="UTF-8"?>
    <manifest xmlns="http://ns.adobe.com/f4m/1.0">
        <id>
    video_400
        </id>
        <streamType>
            recorded
        </streamType>
        <duration>
        87.823999999999998
        </duration>
        <bootstrapInfo profile="named" id="bootstrap9368">
        <metadata>
            ele mele
         </metadata>
        </bootstrapInfo>
    </manifest>



var xmlData:XML = new XML(loader.content as String) ;
var f4mNs : Namespace = xmlData.namespace();
trace(this + " onQueueComplete DURATION= " + xmlData.f4mNs::duration);

Comments

0

Try this:

var email:XMLList = resultXml..Email;

//access the user email
var userEmail:String = String[email.EmailString];

Of course you could access EmailString directly with the dot syntax!

1 Comment

nope. no good :( I posted a screen shot showing this not working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.