Highlighted

Can't access xml tags directly:: Namespace issue

New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

It appears that I've found another case of "Flash does (this) great. EXCEPT . . . . . "

I've posted my issue on a couple forums with no replies. Rather than repost I'll just put the link here and hope SOMEBODY has an answer.

http://www.actionscript.org/forums/showthread.php3?p=1137057#post1137057



Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

oops, you're correct.

i fixed that in message 1 so, you can mark that as correct if you found it helpful.

there are 2 ways a namespace can be used in xml.  the way you are using it, the namespace applies to each and every node within the xml.

to reference each of every node (but not attribute) you must use the namespace string:

trace(xml.s::responseDeclaration.s::mapping.s::mapEntry.@mapKey);

trace(xml.s::responseDeclaration.s::mapping.s::mapEntry.(@mapKey=="A").@mappedValue);

TOPICS
ActionScript

Views

2.0K

Likes

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

Can't access xml tags directly:: Namespace issue

New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

It appears that I've found another case of "Flash does (this) great. EXCEPT . . . . . "

I've posted my issue on a couple forums with no replies. Rather than repost I'll just put the link here and hope SOMEBODY has an answer.

http://www.actionscript.org/forums/showthread.php3?p=1137057#post1137057



Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

oops, you're correct.

i fixed that in message 1 so, you can mark that as correct if you found it helpful.

there are 2 ways a namespace can be used in xml.  the way you are using it, the namespace applies to each and every node within the xml.

to reference each of every node (but not attribute) you must use the namespace string:

trace(xml.s::responseDeclaration.s::mapping.s::mapEntry.@mapKey);

trace(xml.s::responseDeclaration.s::mapping.s::mapEntry.(@mapKey=="A").@mappedValue);

TOPICS
ActionScript

Views

2.0K

Likes

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
Sep 18, 2012 0
Adobe Community Professional ,
Sep 18, 2012

Copy link to clipboard

Copied

you need to use that namespace to reference xml elements.  try:

var s:Namespace=xml.namespace();

trace(xml.s::responseDeclaration);

Likes

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
Reply
Loading...
Sep 18, 2012 0
New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

doesn't work.

the xml is from DITA markup. I know nothing about it. It was given to me with instructions.

Likes

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
Reply
Loading...
Sep 18, 2012 0
New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

putting your code in throws an error:


1046: Type was not found or was not a compile-time constant: NameSpace.

Likes

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
Reply
Loading...
Sep 18, 2012 0
Adobe Community Professional ,
Sep 18, 2012

Copy link to clipboard

Copied

what are your publish settings?

Likes

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
Reply
Loading...
Sep 18, 2012 0
New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

I'm publishing for 3.0 out of CS5

Likes

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
Reply
Loading...
Sep 18, 2012 0
New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

Namespace requires a small s.

I can now trace responseDeclaration. How do I access its children? How does that code even work for that matter?

Likes

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
Reply
Loading...
Sep 18, 2012 0
Adobe Community Professional ,
Sep 18, 2012

Copy link to clipboard

Copied

oops, you're correct.

i fixed that in message 1 so, you can mark that as correct if you found it helpful.

there are 2 ways a namespace can be used in xml.  the way you are using it, the namespace applies to each and every node within the xml.

to reference each of every node (but not attribute) you must use the namespace string:

trace(xml.s::responseDeclaration.s::mapping.s::mapEntry.@mapKey);

trace(xml.s::responseDeclaration.s::mapping.s::mapEntry.(@mapKey=="A").@mappedValue);

Likes

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
Reply
Loading...
Sep 18, 2012 0
New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

Hallalejah.

Thank you very much!

Likes

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
Reply
Loading...
Sep 18, 2012 0
Adobe Community Professional ,
Sep 18, 2012

Copy link to clipboard

Copied

you're welcome.

Likes

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
Reply
Loading...
Sep 18, 2012 0
New Here ,
Sep 19, 2012

Copy link to clipboard

Copied

One last question: Would it be possible to traverse the xml tags using tagnames stored in variables?

The only problem I see with this method is that it's very "static" to type in

xml.s::responseDeclaration.s::correctResponse.s::value

is there a way to say:

var correctAnswer = "responseDeclaration.s::correctResponse.s::value"

to then get

xml.s::child(correctAnswer);

That way dealing with changing xml structures could be handled in the variables section of my code.

Likes

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
Reply
Loading...
Sep 19, 2012 0
Adobe Community Professional ,
Sep 19, 2012

Copy link to clipboard

Copied

i'm not sure what you're asking.  but if you are asking for a short cut to traverse your xml, you can use the double dot:

trace(xml..s::simpleChoice);

Likes

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
Reply
Loading...
Sep 19, 2012 0
New Here ,
Sep 19, 2012

Copy link to clipboard

Copied

While that's helpful, I'm looking for a way to store "simpleChoice" as a string to reference somehow.

as in

xml.s::(string for simpleChoice)

Likes

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
Reply
Loading...
Sep 19, 2012 0
Adobe Community Professional ,
Sep 19, 2012

Copy link to clipboard

Copied

use array notation:

var itemS:String="simpleChoice";

.

.

.

var simpleChoiceList:XMLList = xml..s::[itemS];

Likes

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
Reply
Loading...
Sep 19, 2012 0
New Here ,
Sep 19, 2012

Copy link to clipboard

Copied

kglad, you're the man. Over the past 3 years I've posted probably a half dozen problems on various sights, and you are officially the first one to answer any of them with a solution. (well maybe 2nd, but still)

I tip my hat to you. Thanks!

Likes

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
Reply
Loading...
Sep 19, 2012 0
kglad LATEST
Adobe Community Professional ,
Sep 19, 2012

Copy link to clipboard

Copied

you're welcome!

Likes

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
Reply
Loading...
Sep 19, 2012 0
New Here ,
Sep 18, 2012

Copy link to clipboard

Copied

Can you please explain to me why this works with your code? Everything I've found on the subject doesn't reference a double colon anywhere.
How would I access child nodes of responseDeclaration?

Likes

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
Reply
Loading...
Sep 18, 2012 0