xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arvind Bassi <arvind_ba...@yahoo.co.uk>
Subject Re: Problem: Extracting a String from CDATA Section
Date Wed, 04 Apr 2001 08:44:32 GMT
Further clarification on the problem is as follows.

What is the best way of encapsulating an XML document within another
XML document so that it can later be extracted as a String?

The reason why l need to obtain a String is because l need to store the
original XML string in a database, much later on.

At present, l am passing the original XML document through Xalan,
converting it and the contents of one of the nodes in the transformed
document is the original XML document wrapped as a CDATA Section.

When l view the resulting document, l have:

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

Later on l use 

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

and receive several Node.PROCESSING_INSTRUCTION_NODEs and the root
Node.ELEMENT_NODE of the original XML document. 

It appears that the Xerces' implementation of Document() totally
ignores the CDATA Section and interprets it as merely a Processing
instruction.

Is this because l am using the wrong process to obtain the CDATA
Section, or can't Xerces handle CDATA Section? or do l need to
explicitly state the name of the CDATA Section at the top of the XML
Document?

Thanks.

Arvind.

--- Scott_Boag@lotus.com wrote: > 
> 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
> 


____________________________________________________________
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


Mime
View raw message