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.
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.
So I can get the XML declaration through its string (but only BEFORE parsing; that stinks) or through the legacy XMLDocument class (which I haven't tried yet but will soon).
The XML comes externally and could theoretically have any encoding. Parts of the XML go into text fields onstage, so I want to check if I need to alter display fonts if XML isn't UTF-8.
Thanks
The effort is the need to cast to XMLDocument/parse the string upon data receipt. You're right, it's not difficult. It's just a bad way of doing things. Now I have to insert something "special" at string-parse time just to get the declaration, then figure a way to remember that declaration in case it's needed elsewhere. I'm wondering why xmlDecl was removed from the XML class.
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.
North America
Europe, Middle East and Africa
Asia Pacific