xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Scott_B...@lotus.com
Subject Re: Problem: Extracting a String from CDATA Section
Date Wed, 04 Apr 2001 01:58:55 GMT

Hi Arvind.  I'm a bit confused from your message, and the context that you
are operating in.

> Am l wrong in expecting the child node of "elements" (see above) to be
> a Node.CDATA_SECTION_NODE?

Yes, I think so, though, as I said, I am a bit confused.  CDATA section
nodes are not part of the XPath/XSLT data model (which views them a simply
a lex-time convention for markup), and CDATA section nodes will not by
themselves be created by Xalan.  The only way to get a proper CDATA section
from a *serializer* is via <xsl:output cdata-section-elements ="
Message_text"/>.   However, the CDATA section stuff is handled totally by
the serializer... I don't think org.apache.xpath.DOMHelper will ever handle
the cdata-section-elements information, thus I don't think there's any way
to create a CDATA section in DOM output (which could be considered a bug, I
guess).

I think what you are doing is just creating a single text node with
disable-escaping markers in the DOM.

> <Message_text>
> <![CDATA[
> <Trade_Document>.....</Trade_Document>
> ]]>
> </Message_text>

If you had Xalan create a DOM from your xsl fragment, you will get one text
node inside of the Message_text element.

Not sure if I am helping...

-scott




                                                                                         
                            
                    Arvind Bassi                                                         
                            
                    <arvind_bassi@ya        To:     general@xml.apache.org            
                               
                    hoo.co.uk>              cc:     (bcc: Scott Boag/CAM/Lotus)       
                               
                                            Subject:     Problem: Extracting a String from
CDATA Section              
                    04/03/2001 05:12                                                     
                            
                    PM                                                                   
                            
                    Please respond                                                       
                            
                    to general                                                           
                            
                                                                                         
                            
                                                                                         
                            




I am using Xalan to process a stylesheet and an incoming document, and
one of the nodes that is created is a CDATA node, as so:

                     <Message_text>
                               <xsl:text disable-output-escaping="yes">
                               &lt;![CDATA[
                               </xsl:text>
                                          <xsl:copy-of select="node()"/>
                               <xsl:text disable-output-escaping="yes">

                               ]]&gt;
                               </xsl:text>
                     </Message_text>

becoming:

<Message_text>
<![CDATA[
<Trade_Document>.....</Trade_Document>
]]>
</Message_text>

I am copying the contents of the original document into the
Message_text node.

As part of my development l need to extract the contents of
<Message_text> into a String.

HOWEVER, I AM EXPERIENCING QUITE A FEW PROBLEMS.

Therefore, my code is as follows:

 NodeList elements = doc.getElementsByTagName("Message_text");

If the node was:

      <Message_text>Hello</Message_text>

The children nodes of "elements" is a Node.TEXT_NODE and l can get the
data.

However, if <Message_text> has a CDATA section then the children nodes
are (the separate values are separated by "|" pipes):

NODETYPE|NODENAME|NODEVALUE|hasChilren?
Node.PROCESSING_INSTRUCTION|javax.xml.transform.disable-output-escaping|false

Node.TEXT_NODE|#text|<![CDATA[|false
Node.PROCESSING_INSTRUCTION|javax.xml.transform.disable-output-escaping|false

Node.ELEMENT_NODE|Trade_Document|true
Node.PROCESSING_INSTRUCTION|javax.xml.transform.disable-output-escaping|false

Node.TEXT_NODE|#text|<![CDATA[|false
Node.PROCESSING_INSTRUCTION|javax.xml.transform.disable-output-escaping|false


Am l wrong in expecting the child node of "elements" (see above) to be
a Node.CDATA_SECTION_NODE?

(and thus just use String s = node.getNodeValue() to get the value)

Is this a bug, or am l approaching the problem the wrong way?

Arvind.



____________________________________________________________
Do You Yahoo!?
Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
or your free @yahoo.ie address at http://mail.yahoo.ie

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org






---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Mime
View raw message