Skip navigation
Currently Being Moderated

get XML declaration

May 20, 2009 2:14 PM

this should be easy, but I can't figure it. How do I get an XML declaration in AS3? I need to get any encoding= parameter. For example this XML:

<?xml version="1.0" encoding="UTF-8"?>

<some>

<thing>...</thing>

</some>

 

It's XML text that loads externally from a URL using URLLoader. I create the XML object by doing var xml:XML = new XML(evt.target.data) upon load complete. I've tried XML.ignoreProcessingInstructions = false and no effect. xml.children()[0] is the first node, not the declaration. Do I need to manually parse the raw string data that is returned from URLLoader? That seems silly.

 
Replies
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    May 20, 2009 2:48 PM   in reply to tedalde2

    if you cast that data as an XMLDocument instance, you can use its xmlDecl property.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    May 20, 2009 5:14 PM   in reply to tedalde2

    i don't know if you need to but it solves the problem.

     
    |
    Mark as:
  • Currently Being Moderated
    May 20, 2009 6:49 PM   in reply to tedalde2

    You can get the processingInstructions if they are not ignored during parsing (XML.ignoreProcessingInstructions=false) but NOT (apparently, it seems) xml processing instructions.

     

    I don't know if its true, but according to : http://community.adobe.com/help/profile/index.html?id=553464C04456C36B 9920157F, in the comments at the bottom of the page here:http://help.adobe.com/en_US/AS3LCR/Flash_10.0/XML.html

     

    it's not relevant as as3 always uses version 1 and UTF-8 .

     

    Either way, if you don't want to use kglad's approach- which does seem to be one viable option- and if you're loading it at runtime, you can easily get it before parsing, because it's simply the first part of the data string on the URLLoader before its parsed.

     
    |
    Mark as:
  • kglad
    72,212 posts
    Jul 21, 2002
    Currently Being Moderated
    May 21, 2009 7:30 AM   in reply to tedalde2

    yes.  but i don't understand the problem.

     

    even if there was some need to know the declaration, there's no significant effort required to determine the declaration.

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 10, 2010 2:58 AM   in reply to tedalde2

    There is also the problem of how do you emit the XML tag when you write out an XML object.  I'd like to save an XML file in the same format as the file I read in, i.e. including "<?xml version="1.0" encoding="UTF-8"?>" as the first line, and I haven't been able to figure out how to do that.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points