You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Arvind Bassi <ar...@yahoo.co.uk> on 2001/04/03 23:09:19 UTC

Problem: Extracting String value from CDATA Section

I am a Newbie, so please be kind.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org