Skip to main content
Inspiring
January 9, 2012
Answered

XML Writing "<" or ">" AKA < or >

  • January 9, 2012
  • 1 reply
  • 2758 views

Hi there,

How do I write a less than or greater than symbol to an xml file? The code works but the resulting XML file contains the named character entity reference in place of the less than or greater than sign.

I need the xml to refer to Cascading Style Sheets. If we build the xml manually, everything works fine. We are trying to build a utility with AIR to create the xml for us, based on contents of fields on an AIR form. Everything works before we try to add "![CDATA[<p>" as the opening tag.

Out of despiration, we've tried a number of things. The latest is using variables to hold the strings we want to write as in what you see next:

var cDataStart:String = "![CDATA[<p>";

var cDataEnd:String = "</p>]]";

newElements.DragDropContainer.appendChild(<DragDrop><Labels name={Match}>{cDataStart+fileName+cDataEnd}</Labels><Targets image={png}value ={Match}></Targets></DragDrop>);

This results in this XML:

    <DragDrop>

      <Labels name="Match0">![CDATA[&lt;p&gt;label&lt;/p&gt;]]</Labels>

      <Targets image="image3.png" value="Match0"/>

    </DragDrop>

Thoughts anyone?

Thanks

Pete H.

This topic has been closed for replies.
Correct answer kglad

Good thought but you are correct... it wasn't the problem.

I tried it and got this in the resulting xml file:

      <Labels name="Match0">&lt;![CDATA[&lt;p&gt;l&lt;/p&gt;]]</Labels>

I've already built something like this in another dev system but I didn't use any built in functions to add nodes/tags or any other xml specfic things. I just wrote the text file. I'm guessing that if this is going to work in AIR, we will have to follow that same approach and just ignore all the built in functions... not ideal and I hope someone will suggest a solution.

Thanks,

Pete H.


it's the 2nd part of my message that addresses the problem you're seeing:  you're using the cdata and it's value as a string instead of xml. 

for example, use:

function cdataF(s:String):XML{

    var xml:XML = new XML("<![CDATA["+s+"]]>");

    return xml;

}

var xml:XML = <DragDrop><Labels>{cdataF("<p>"+fileName+"</p>")}</Labels></DragDrop>;

1 reply

kglad
Community Expert
Community Expert
January 9, 2012

copy and paste your urlloader code.

Pete47Author
Inspiring
January 9, 2012

This is code I've inherited from my Flash developer. She has sort of given up on making this work. However, we need this to work...

In this version of the utilty she isn't opening an xml file, she is only creating one. So I think that explains why I don't see any urlloader code.

Basically she gathers all the text information for the new xml file from various fields and the writes them to the new xml file.

Is there a different approach we need to take in order to be able to write everything we need to the new xml file?

Thanks,

Pete H.

kglad
Community Expert
Community Expert
January 9, 2012

how is she writing a new xml file if not using a urlloader????