You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Mihai Matei <mi...@yahoo.com> on 2007/05/14 17:25:17 UTC
How can I get the contents of a CDATA section?
Hi,
sample file:
<?xml version="1.0" encoding="UTF-8"?>
<test>
<SupplementalAction>
<![CDATA[#!/usr/bin/ksh
other stuff
]]>
</SupplementalAction>
</test>
sample code that does not work:
DOMNode *temp = pDoc->getElementsByTagName(X("SupplementalAction"))->item(0);
const XMLCh* contents = temp->getFirstChild()->getNodeValue();
char* strValue = XMLString::transcode(contents);
std::cout << "\nCDATA:" <<strValue;
What am I doing wrong? Any help appreciated.
Is there any way of printing the in-memory DOM structure?
Thanks.
____________________________________________________________________________________
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097
RE: How can I get the contents of a CDATA section?
Posted by Jesse Pelton <js...@PKC.com>.
First you need to understand what goes in the DOM. In your example, the
first child of the SupplementalAction element is a text node containing
whitespace. Then comes the character data, then more whitespace. If
all you're interested is the contents of the CDATA section, traverse the
list of children using DOMNode::getFirstChild() and
DOMNode::getNextSibling(). Use DOMNode::getNodeType() to check the type
of each node, and when you find one whose type is
DOMNode::CDATA_SECTION_NODE, cast it to DOMCharacterData and call
DOMCharacterData::getData(). (I'm not 100% certain of that last step,
not having done that bit myself.)
Alternately, DOMNode::getTextContent() might serve your purposes.
-----Original Message-----
From: Mihai Matei [mailto:mihaimilk@yahoo.com]
Sent: Monday, May 14, 2007 11:25 AM
To: c-users@xerces.apache.org
Subject: How can I get the contents of a CDATA section?
Hi,
sample file:
<?xml version="1.0" encoding="UTF-8"?>
<test>
<SupplementalAction>
<![CDATA[#!/usr/bin/ksh
other stuff
]]>
</SupplementalAction>
</test>
sample code that does not work:
DOMNode *temp =
pDoc->getElementsByTagName(X("SupplementalAction"))->item(0);
const XMLCh* contents = temp->getFirstChild()->getNodeValue();
char* strValue = XMLString::transcode(contents);
std::cout << "\nCDATA:" <<strValue;
What am I doing wrong? Any help appreciated.
Is there any way of printing the in-memory DOM structure?
Thanks.
________________________________________________________________________
____________
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight
and hotel bargains.
http://farechase.yahoo.com/promo-generic-14795097