I have the following code snippet to traverse a NodeList (all element
nodes retrieved using getElementsByTagName). The getNodeName() retrieves
the correct name. However, the getNodeValue() is not printing out the
value. (We have tried dynamic_cast of xNode3 to a DOMElement also but
this also doesn't work. We have also tried using getFirstChild()/
getNextSibling() instead of the below for-loop - but same result. The
NodeName returns the correct value but the NodeValue doesn't)
Can someone please help identifying the problem?
The parser used is XercesDOMParser - parsing a XML using a
MemBufInputSource (rather than a XML file)
DOMNodeList* xNodeList3 = xNode->getChildNodes();
const XMLSize_t ixNodeCount3 = xNodeList3->getLength();
for (int i3=0; i3<ixNodeCount3; i3++)
{
DOMNode* xNode3 = xNodeList3->item(i3);
if (DOMNode::ELEMENT_NODE == xNode3->getNodeType())
{
char* sxNode3Name =
XMLString::transcode(xNode3->getNodeName()); // OK
char* sxNode3Value =
XMLString::transcode(xNode3->getNodeValue()); //
retrieves null string
cout << "Rule: " << (i+1) << "\tNode: " << sxNode3Name <<
"\tValue: " << sxNode3Value<< endl;
XMLString::release(&sxNode3Name);
XMLString::release(&sxNode3Value);
}
}
delete xNodeList3;
The XML string used:
const string sXML = "<?xml version='1.0'?>\
<kfRuleSet>\
<kfRule valueType='CONTENT'>\
<kfStart>11</kfStart>\
<kfEnd>15</kfEnd>\
</kfRule>\
<kfRule valueType='STATIC'>\
<kfText>-</kfText>\
</kfRule>\
</kfRuleSet>";
Actual Output
Rule: 1 Node: kfStart Value:
Rule: 1 Node: kfEnd Value:
Rule: 2 Node: kfText Value:
Expected Output
Rule: 1 Node: kfStart Value: 11
Rule: 1 Node: kfEnd Value: 15
Rule: 2 Node: kfText Value: -
**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are
not to copy, disclose, or distribute this e-mail or its contents to any other
person and any such actions are unlawful. This e-mail may contain viruses.
Infosys has taken every reasonable precaution to minimize this risk, but is not
liable for any damage you may sustain as a result of any virus in this e-mail.
You should carry out your own virus checks before opening the e-mail or
attachment. Infosys reserves the right to monitor and review the content of all
messages sent to or from this e-mail address. Messages sent to or from this
e-mail address may be stored on the Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***