Skip to main content
Inspiring
June 27, 2008
Answered

& in XML

  • June 27, 2008
  • 3 replies
  • 1221 views
This is an offshoot question from this post, for which the original question was answered. Thanks for the help, Rothrock.

Anyway, the new problem in my AS3 project is that my XML requires a tag to contain an ampersand. Flash, being a slave to the All-Powerful Ampersand, only seems to be able to spit out the code &amp. I've done some research on this, but haven't found a workable answer for how to force an XML node to contain an ampersand. nodeValue doesn't appear to work as it did in AS2.

This is what I need to encode in my tag: <mytag>Line One of Text&#13;Line Two of Text</mytag>
The destination program must have the line feed in this format (&#13;).

Any thoughts?

Thanks... these boards are invaluable...
-SyddyS
This topic has been closed for replies.
Correct answer SyddyS
Yup. Great minds, Rothrock. After my last post I started playing around with string methods. Here's the workflow to solve the problem:
1. Import the XML file
2. Do whatever you need to do to it using XML methods
3. Add the attached code
4. Export myData instead of template_xml
5. Go have a beer because you're done.

I would assume this will work with any issues derived from Flash's handling of special XML characters. For anyone who's curious who might read this, make sure you have the "g" (for "global") at the end of the RegExp, otherwise it just finds and replaces the first instance.

Thanks for the help, folks! Now I can actually get some work done!
-SyddyS

3 replies

SyddySAuthorCorrect answer
Inspiring
June 27, 2008
Yup. Great minds, Rothrock. After my last post I started playing around with string methods. Here's the workflow to solve the problem:
1. Import the XML file
2. Do whatever you need to do to it using XML methods
3. Add the attached code
4. Export myData instead of template_xml
5. Go have a beer because you're done.

I would assume this will work with any issues derived from Flash's handling of special XML characters. For anyone who's curious who might read this, make sure you have the "g" (for "global") at the end of the RegExp, otherwise it just finds and replaces the first instance.

Thanks for the help, folks! Now I can actually get some work done!
-SyddyS
Inspiring
June 27, 2008
A quick thought. Is there anyreason that flash even needs to know this is XML? It could just be a string. Perhaps that would help.
Inspiring
June 27, 2008
One of the important ways to deal with special characters is to structure you XML in a such a way that the strings potentially containing special characters are inside CDATA:

<![CDATA[Your string here]]>

Whatever is within CDATA will not be parsed.

Otherwise result are really unpredictable.
SyddySAuthor
Inspiring
June 27, 2008
Maybe I haven't had enough coffee yet...
Using the example above, here's the situation:
I have an XML document that has been imported. That document contains a tag called <mytag>, and I'm trying to set the value of <mytag> to "Line One of Text&#13;Line Two of Text" so that the end result is this:
<mytag>Line One of Text&#13;Line Two of Text</mytag>

I then want to export the document with the formatting intact. I tried setting the value using:
my_xml.something.something.mytag = ![CDATA[LineOne&#13;Line Two]];
But I've got a feeling that's not what you meant. Got "access of undefined property CDATA" error on that one...
I cannot change the overall structure of the XML file, as the program that will ultimately import it is extremely fussy (Final Cut Pro). So the end result must look like the example above...

I'm so close on this one... I'd hate to be foiled by a line feed.

Thanks,
SyddyS


Inspiring
June 27, 2008
Try: my_xml.something.something.mytag = <![CDATA[LineOne&#13;Line Two]]>;

OR
my_xml.something.something += <mytag><![CDATA[LineOne&#13;Line Two]]></mytag>;

there are other variations of the syntax you can use.