On Wed, May 09 2001 at 12:25:02P +1000, Krishna Gadde wrote:
> Hi All,
>   I am using xerces-c to parse my xml file.using
> this i am not able to read PCDATA present between the tags.
> I tried with the following method to retrieve the data.
> DOM_Node.getNodeValue();
> Can you please suggest the method which will be used to read the PCDATA.
> Regards,
> krishna

  Since I struggled with this for a bit.... The following function
has two sections, one detailed out step by step (and also #if'd out
of existence) and a briefer version.

  The dtd would be: <!ELEMENT p_sTag (#PCDATA)>

  One question -- does Xerces distinguish between #PCDATA and CDATA?
The code below is reading CDATA. Is there a way to read #PCDATA?

//
// Reads an integer from the document. The enclosing tags must be p_sTag.
//
void ReadIntWithTag( DOM_Document & doc_, int & iValue, const string & p_sTag )
{
#if 0
  // Get a DOM_NodeList of elements tagged p_sTag
  DOM_NodeList cElem = doc_.getElementsByTagName(DOMString(p_sTag.c_str()));
  // Get the first (which should be the only) one
  DOM_Node cNode = cElem.item(0);
  // Get a DOM_NodeList of its children
  DOM_NodeList child = cNode.getChildNodes();
  // Get the first (which should be the only) DOM_CDATASection
  DOM_CDATASection cdata = ( const DOM_CDATASection & ) child.item(0);
  // Get the data contained therein and convert it to a string.
  string s ( cdata.getData().transcode() );
  iValue = atoi( s.c_str() );
#endif // #if 0

  // We don't need to be so verbose as above...
  DOM_Node cNode = doc_.getElementsByTagName(DOMString(p_sTag.c_str())).item(0);
  DOM_CDATASection cdata = ( const DOM_CDATASection & ) 
(cNode.getChildNodes().item(0));
  iValue = atoi( cdata.getData().transcode() );
}

  Thanks in advance,
  Dee Jay

+-----------------------------+------------------+-----------------------+
| Founding Partner            | Software Engineer| Dee Jay Randall, B.Sc.|
| Circular Reasoning          | Accrue Software  | M.Sc. Student, CS     |
| [EMAIL PROTECTED]| www.accrue.com   | ICQ # 43551676        |
+-----------------------------+------------------+-----------------------+
What is the average rank of every song ever written? 42  -- www.launch.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to