I am trying to create an XML object that includes cdata. My
code looks like this:
var myXMLObj:XML;
myXMLObj.myNewNode = ''%26lt;![CDATA[ Here is some HTML
%26lt;br/%26gt; And a variable: '' + myVariable + '' ]]%26gt;'';
The result of this is that all the %26lt; and %26gt; characters
get HTML encoded as they are added to myXMLObj. I need the XML to
look like this:
%26lt;myNewNode%26gt;%26lt;![CDATA[ Here is some HTML %26lt;br/%26gt;
And a variable: value ]]%26gt;%26lt;/myNewNode%26gt;
but it ends up looking like this:
%26lt;myNewNode%26gt;%26amp;lt;![CDATA[ Here is some HTML
%26amp;lt;br/%26amp;gt; And a variable: value
]]%26amp;gt;%26lt;/myNewNode%26gt;
I tried the following (none of which worked):
myXMLObj.myNewNode = ''%26amp;lt;![CDATA[ Here is some HTML
%26amp;lt;br/%26amp;gt; And a variable: '' + myVariable + '' ]]%26amp;gt;'';
myXMLObj.myNewNode = XML(''%26lt;![CDATA[ Here is some HTML
%26lt;br/%26gt; And a variable: '' + myVariable + '' ]]%26gt;'');
myXMLObj.myNewNode = ''\%26lt;![CDATA[ Here is some HTML
\%26lt;br/\%26gt; And a variable: '' + myVariable + '' ]]\%26gt;'';
myXMLObj.myNewNode = unescape(''%26lt;![CDATA[ Here is some HTML
%26lt;br/%26gt; And a variable: '' + myVariable + '' ]]%26gt;'');
Anybody know how to include characters like %26lt;, %26gt;, and
%26amp; in a String object that's going into an XML object?XML and CDATA
Anybody knows the answer to this issue?
''Anybody know how to include characters like %26lt;, %26gt;, and
%26amp; in a String object that's going into an XML object?''
I''m trying to add HTML text to an XML object and I''m having
the same issue.XML and CDATA
Hi,
I had a similar requirement , but the only difference was
that I converted string objects into XML.
Use XML() function to convert your string into xml.
Ex:
var itemStr:String=%26lt;br/%26gt;
var myXMLObj:XML;
myXMLObj.myNewNode =XML(itemStr)
Hope this works.
I havent tested this as my flex builder 2 is uninstalled.
Good Luck.
Thanks for the input. I tried what you suggested but it
didn't work. There must be a way to add HTML tags to an XML object
in Flex. Any Flex guru out there would like to help? I've been
struggling with this problem for awhile.
This is what my code looks like in an AS class:
var mainXML:XML = %26lt;entries%26gt; %26lt;/entries%26gt;;
var itemXML:XML =
%26lt;entry%26gt;
%26lt;date%26gt;%26lt;/date%26gt;
%26lt;headline%26gt;%26lt;/headline%26gt;
%26lt;detail%26gt;%26lt;/detail%26gt;
%26lt;/entry%26gt;
itemXML.date = ''05/10/2007'';
itemXML.headline =''%26lt;![CDATA[ %26lt;b%26gt;My
Headline%26lt;/b%26gt; ]]%26gt;'';
itemXML.detail =''%26lt;![CDATA[ %26lt;b%26gt; Body Text %26lt;/b%26gt;
]]%26gt;'';
mainXML = mainXML.appendChild(itemXML);
//
trace(mainXML.toString())
Trace results:
Notice the ''%26lt;'' and ''%26gt;'' got encoded.
%26lt;entries%26gt;
%26lt;entry%26gt;
%26lt;date%26gt;05/10/2007%26lt;/date%26gt;
%26lt;headline%26gt;%26amp;lt;![CDATA[ %26amp;lt;b%26amp;gt;My
Headline%26amp;lt;/b%26amp;gt; ]]%26amp;gt;%26lt;/headline%26gt;
%26lt;detail%26gt;%26amp;lt;![CDATA[ %26amp;lt;b%26amp;gt; Body Text
%26amp;lt;/b%26amp;gt; ]]%26amp;gt;%26lt;/detail%26gt;
%26lt;/entry%26gt;
%26lt;/entries%26gt;
Thanks for the input. I tried what you suggested but it
didn't work. There
must be a way to add HTML tags to an XML object in Flex. Any
Flex guru out
there would like to help? I've been struggling with this
problem for awhile.
This is what my code looks like in an AS class:
var mainXML:XML = %26lt;entries%26gt; %26lt;/entries%26gt;;
var itemXML:XML =
%26lt;entry%26gt;
%26lt;date%26gt;%26lt;/date%26gt;
%26lt;headline%26gt;%26lt;/headline%26gt;
%26lt;detail%26gt;%26lt;/detail%26gt;
%26lt;/entry%26gt;
itemXML.date = ''05/10/2007'';
itemXML.headline =''%26lt;![CDATA[
My Headline ]]%26gt;'';
itemXML.detail =''%26lt;![CDATA[
Body Text ]]%26gt;'';
mainXML = mainXML.appendChild(itemXML);
//
trace(mainXML.toString())
Trace results:
Notice the ''%26lt;'' and ''%26gt;'' got encoded.
%26lt;entries%26gt;
%26lt;entry%26gt;
%26lt;date%26gt;05/10/2007%26lt;/date%26gt;
%26lt;headline%26gt;%26lt;![CDATA[ %26lt;b%26gt;My Headline%26lt;/b%26gt;
]]%26gt;%26lt;/headline%26gt;
%26lt;detail%26gt;%26lt;![CDATA[ %26lt;b%26gt; Body Text %26lt;/b%26gt;
]]%26gt;%26lt;/detail%26gt;
%26lt;/entry%26gt;
%26lt;/entries%26gt;
Even I m facing the Same problem, No body is there who knows
about this. How can we include HTML data in xml. Since some tags
are not in xml format.
And what about, display of HTML data, Flex don't have a
component to display HTML data Also.
I am experiencing the same problem. I posted too fast, here
is mine:
http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60%26amp;catid=58 5%26amp;threadid=1298339%26amp;highlight_key=y%26amp;keyword1=CDATA
Normally, it should be possible to replace a '%26lt;' with a
'%26amp;lt;' and '%26gt;' with '%26amp;gt;', so that you can use the rest
as a normal text string without using CDATA.
Example:
%26lt;myXMLTag%26gt;%26amp;lt;myHTMLTag%26amp;gt;What a nice HTML tag
here%26amp;lt;/myHTMLTag%26amp;gt;%26lt;/myXMLTag%26gt;
Although, I don't have tested this in a Flex
environment.
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment