Have you tried not using cdata at all?  If your html text is xml
compliant (XHTML) then you can use xpath to get the value of the node
and return it.  Then you load the text.  I just had to solve the same
problem and it worked beautifully.  

XPath select Nodes returns an array of child nodes.  Take the returned
array and join it using and empty string and you now have a string of
html text. Then use css to mark it up and you're done.  


Here is the function that loads the xml:

function loadXml(){
        //trace("load xml called");
        
        this.xml = new XML();
        this.xml.ignoreWhite = true;
        this.xml._parent = this;
        
        this.xml.onLoad = function () {
                //trace("xml loaded");
                this._parent.headertext =
XPath.selectNodesAsString(this, "/page/h1/text()");
                var c  = XPath.selectNodes(this,
"/page/content/node()");
                this._parent.contenttext = c.join("");
                //trace("header text <::> "+this._parent.headertext);
                //trace("content text <::> "+this._parent.contenttext);

                // resume the load manager to load the next item 
                this._parent.loadManager.resume();
        }
        // this.datafile is just the path to the xml file
        this.xml.load(this.datafile);
}


Here is the xml:

<?xml version="1.0" encoding="iso-8859-1"?><?xml version="1.0"
encoding="iso-8859-1"?>

<page>
        <h1>This is the name of the page</h1>
        <content>


<h2>This is a second level header</h2><br/>

<p>blah lbha lbhh Blah </p><br/>

<h2>This is a header</h2><br/>

<p>more content</p><br/>

<h2>another header</h2><br/>

<p>blah blah </p><br/>
        
        </content>
</page>



-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Merrill,
Jason
Sent: Friday, February 03, 2006 9:31 AM
To: Flashcoders mailing list
Subject: RE: [Flashcoders] Question about xpath and cdata

This is the only thing I have found that works:

XMLNode((XPath.selectNodes(myXML,"root/node/text()")[0])).nodeValue;

Ugly isn't it?

Jason Merrill   |   E-Learning Solutions   |  icfconsulting.com










>>-----Original Message-----
>>From: [EMAIL PROTECTED] [mailto:flashcoders-
>>[EMAIL PROTECTED] On Behalf Of Mark Burvill
>>Sent: Friday, February 03, 2006 11:20 AM
>>To: Flashcoders mailing list
>>Subject: Re: [Flashcoders] Question about xpath and cdata
>>
>>Anyone?
>>
>>:o)
>>
>>Mark Burvill wrote:
>>
>>> Hi everyone,
>>>
>>> I'm still a bit new to using xml with flash, and I'm just starting
to
>>> dig into xfactorstudio's xpath for AS2.
>>> I'm generally loving the way it's clearly going to save me loads of
>>> time in searching through my xml docs, but I'm having a bit of a
>>> probem getting html formatted text from a CDATA tag to display
>>> properly....
>>>
>>> Say this is my xml file:
>>>
>>> <content>
>>>    <biog>
>>>        <![CDATA[Lorem ipsum dolor<br><br>sit amet.]]>
>>>    </biog>
>>> </content>
>>>
>>> What I'm trying to do is get the "Lorem ipsum" text and display it
in
>>> an html text field in Flash.
>>>
>>> I would normally do something like this:
>>> var myText:String =
myXML.firstChild.firstChild.firstChild.nodeValue;
>>>
>>> Using "nodeValue" makes sure that the text gets treated as html, and
>>> the line breaks work properly rather than doing:
>>> var myText:String =  myXML.firstChild.firstChild.firstChild;
>>> ... which would display "Lorem ipsum dolor<br><br>sit amet." in my
>>> textfield - not good.
>>>
>>> My question is, how do I get the same result using xpath?
>>>
>>> Doing this:
>>> XPath.selectNodes (myXML, "/content/biog/text()");
>>> ..gives me the right text, but won't treat it as html.
>>>
>>> Thanks!
>>>
>>> Mark.
>>>
>>
>>--
>>*Mark Burvill*
>>Interactive designer
>>www.eyegas.com <http://www.eyegas.com>
>>
>>*Work:* 0117 953 0100
>>*Mobile*: 07780 608498
>>
>>_______________________________________________
>>Flashcoders mailing list
>>[email protected]
>>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
NOTICE:
This message is for the designated recipient only and may contain
privileged or confidential information. If you have received it in
error, please notify the sender immediately and delete the original. Any
other use of this e-mail by you is prohibited.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to