You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Vikram A K Gupta <Vi...@infosys.com> on 2007/07/23 14:13:10 UTC
Xerces - Modifying a value in XPath
Hi All,
Requirement: Basically I need to replace/modify a value at a specified XPath Location in XML message
Approach: I am using following code snippet to achieve the same but it is failing on the location
with the following comment in the snippet: // EXCEPTION BEING THROWN HERE
Any clue how to resolve it and also an alternative approach to achieve the requirement !!
Thanks for helping !!
static XercesDOMParser parser;
// Create an input source...
MemBufInputSource memBufIS( reinterpret_cast<const XMLByte*>(message.c_str()),
XalanDOMString::length(message.c_str()),
"SourceXML",
false );
parser.setValidationScheme(XercesDOMParser::Val_Never);
parser.parse( memBufIS );
DOMDocument* doc = parser.getDocument();
DOMElement* docElement = doc->getDocumentElement();
DOMXPathEvaluator* theEvaluator = (DOMXPathEvaluator *) doc;
char csResolver[] = "/*[local-name()='FpML']";
XMLCh* XMLResolver = XMLString::transcode(csResolver);
DOMNodeList* pList = docElement->getElementsByTagName(XML_le);
DOMNode* pode = pList->item(0);
// EXCEPTION BEING THROWN HERE
const DOMXPathNSResolver* resolver = doc->createNSResolver(pode);
DOMXPathResult *pReult;
char mappingRule[] = "/*[local-name()='FpML']/*[local-name()='header']/*[local-name()='sentBy']";
XMLCh* XMLRule = XMLString::transcode(mappingRule);
xpres = (DOMXPathResult *)theEvaluator->evaluate(XMLRule,
doc->getDocumentElement(),
resolver, DOMXPathResult::FIRST_ORDERED_NODE_TYPE, NULL);
DOMNode* pNode = xpres->getSingleNodeValue();
XMLCh* XML_Val = XMLString::transcode(mappingValue);
pNode->setNodeValue(XML_Val);
**************** 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***
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org