This isn't a Xerces-specific problem; you're not using DOM correctly here.

See

  http://xerces.apache.org/xerces-c/apiDocs-3/classDOMNode.html#_details

for the description of the various attributes of a DOM Node in a convenient
table. For a DOMElement, as you have, the nodeValue is NULL.

In the DOM data model, elements do not have textual values. Instead, they
have 0 or more Text nodes as children, which have the textual values. You
need to navigate to the DOMNode representing the Text node, and then call
getNodeValue() on that. (It will be of class DOMText.)

FYI, the primary reason for this is to support mixed content, eg. elements
like

  <elem>This is an element with <b>mixed</b> content</elem>

Here, the DOMElement representing <elem> will have three direct children: A
text node with the value "This is an element with "; a DOMElement
representing <b>; and another text node with the value " content".  The <b>
DOMElement in turn will have a single DOMText child, with the value "mixed".
This situation could not be adequately represented if the <elem> DOMElement
itself had a textual node value.

In your particular case, if you're sure that you're not dealing with mixed
content, there is a convenience method you may use:
DOMNode::getTextContent(). As the documentation says, it concatenates the
textual value of all children, which in your example will just be the single
text node containing the information you want.

One aside:

  if( currentNode->getNodeType() && currentNode->getNodeType() ==
> DOMNode::ELEMENT_NODE )
>   {
>      DOMElement* currentElement = dynamic_cast< xercesc::DOMElement* >(
> currentNode );
>

You should most likely use static_cast<> here. dynamic_cast<> depends on
run-time type information, and involves significant run-time overhead. Since
you've already checked that the DOMNode is in fact of type ELEMENT_NODE, it
is safe to use static_cast<DOMElement*>.

Hope that helps,
Ceej
aka Chris Hillery

Reply via email to