• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

get XML declaration

Participant ,
May 20, 2009 May 20, 2009

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

2.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2009 May 20, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 20, 2009 May 20, 2009

Copy link to clipboard

Copied

Why would I need to use a legacy class to do this? That seems equally silly. Is it because E4X syntax doesn't specify/require the declaration?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 20, 2009 May 20, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
May 20, 2009 May 20, 2009

Copy link to clipboard

Copied

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=553464C04456C36B9920157F, 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 21, 2009 May 21, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 21, 2009 May 21, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 21, 2009 May 21, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 10, 2010 Dec 10, 2010

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines