You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by David Bertoni <db...@apache.org> on 2007/08/01 18:00:44 UTC

Re: Xalan (with Xerces) - Modify a value at a Node

Vikram A K Gupta wrote:
> Hi All,
> 
> Background
> - We are developing a generic cross reference task for a middleware application.
> - We will be processing multiple XML formats and the plan is to have a single instance of the new cross reference task.
> - We plan on configuring XPATH rules to extract a value (extraction is processed by another task and is complete)
> - After obtaining the value from the XML, we will do a cross reference look-up via a database and then look to repopulate the new value back in the msg via the original XPATH rule,
> 
> The issue we are having is around the re-insertion of the value.
> Approach that we are using:
>                1) XercesLiaisonParser to parse message
>                2) XPathEvaluator to identify a particular node
>                3) XalanNode::setNodeValue to modify the value
> But we are getting 'Unknown exception' when i try to do XalanNode::setNodeValue. Any pointers to resolve it ?
> Following is code snippet but it is failing with the UNKNOWN EXCEPTION
It should not an "unknown" exception, it should be a XalanDOMException. 
Here's a snippet from the source code:

void
XalanSourceTreeElement::setNodeValue(const XalanDOMString&		/* nodeValue */)
{
	throw XalanDOMException(XalanDOMException::NO_MODIFICATION_ALLOWED_ERR);
}

> 
> Any clue how to resolve it and also an alternative approach to achieve the requirement !!
> 
> try{
> 
>     // We'll use these to parse the XML file.
>     XercesDOMSupport theDOMSupport;
>     XercesParserLiaison theLiaison(theDOMSupport);
> 
>     // Create an input source...
>     const MemBufInputSource theInputSource( reinterpret_cast<const XMLByte*>(message.c_str()),
>     XalanDOMString::length(message.c_str()),
>     "SourceXML",
>     false );
> 
>     // Parse the XML Stream
>     XalanDocument* const theDocument = theLiaison.parseXMLStream(theInputSource);
>     XPathEvaluator      theEvaluator;
>     XalanNode* const theContextNode = theDocument->getDocumentElement();
> 
>     //Retrieve the XalanNode for the compiled XPath
>     XalanNode* pXalanNode, *pConstNode = NULL;
>     pConstNode =  theEvaluator.selectSingleNode (theDOMSupport,
>     theContextNode,
>     *m_compiledXPATH);
> 
>     XalanDOMString xalanDOMString("NewValue");
>     pConstNode->setNodeValue(xalanDOMString);    // UNKNOWN EXCEPTION BEING THROWN
> 
>     }
>     catch(const XalanDOMException& xde)
>     {
>     }
>     catch(const DOMException& de)
>     {
>     }
>     catch (...) // UNKNOWN EXCEPTION BEING CAUGHT HERE
>     {
>     }
Unless the node is a null pointer, and you're not checking for that, I 
don't know why you're getting an unknown exception.  Often, running your 
code in a debugger will help with determining what's wrong.

However, your approach will not work, as the Xalan-C source tree is not 
mutable.  The typical way to handle this is to either use the Xerces-C 
source tree with the Xalan-C wrappers, or write an XSLT stylesheet that 
does the transformation, changing the values as appropriate.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


Re: Xalan (with Xerces) - Modify a value at a Node

Posted by David Bertoni <db...@apache.org>.
Vikram A K Gupta wrote:
> Thanks David for helping out !!
> 
> Few more questions: What advantage XSLT Stylesheet approach has over Xerces-C Source tree/Xalan C Wrappers approach ?
The advantage of a stylesheet-based approach is that it is completely 
standard, so you can use any XSLT processor that fits your needs.

> 
> Also we are able to achieve the objective through XSLT Stylesheet but requirement is that we need to implement it by using the Xerces-C
> source tree with the Xalan-C wrappers itself !! We saw couple of posting on this group and tried to implement it as following, It isn't working !! Also Classes DOMParser, DOM_Document, XercesDocumentBridge are all deprecated.  So what classes should be used instead of these. Also How can we implement the requirement using Xerces-C Source tree with Xalan-C wrapper approach !!
The "bridge" classes for the old Xerces DOM are deprecated because the old 
DOM itself is deprecated and now gone in the latest version of Xerces-C. 
You should use the "wrapper" classes instead.  If you look in the archives 
of the Xalan-C User list (which is where you should be posting these sorts 
of questions), you'll find lots of information about using the wrapper classes.

However, if your processing flow involves changing the Xerces-C DOM then 
re-serializing it as XML, I suggest you consider an XSLT-based approach as 
it will be much cleaner.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


RE: Xalan (with Xerces) - Modify a value at a Node

Posted by Vikram A K Gupta <Vi...@infosys.com>.
Thanks David for helping out !!

Few more questions: What advantage XSLT Stylesheet approach has over Xerces-C Source tree/Xalan C Wrappers approach ?

Also we are able to achieve the objective through XSLT Stylesheet but requirement is that we need to implement it by using the Xerces-C
source tree with the Xalan-C wrappers itself !! We saw couple of posting on this group and tried to implement it as following, It isn't working !! Also Classes DOMParser, DOM_Document, XercesDocumentBridge are all deprecated.  So what classes should be used instead of these. Also How can we implement the requirement using Xerces-C Source tree with Xalan-C wrapper approach !!

   DOMParser                      parser;
   parser.parse(InputSource);
   DOM_Document            xercesDocument = parser.getDocument();
   XercesDOMSupport     domSupport;
   XercesParserLiaison   parserLiaison(domSupport);

   XalanDocument* const       xalanDoc =   parserLiaison.createDocument(xercesDocument);
   XercesDocumentBridge*   doc = parserLiaison.mapDocument(xalanDoc);
   XalanNodeList*      nl = doc->getChildNodes();
   const unsigned int  count = nl->getLength();

   for (unsigned int i = 0; i < count; ++i)
   {
       XalanNode* const  current = nl->item(i);
       DOM_Node          xercesNode(doc->mapNode(current));

       // Change the Node Value
   }

________________________________________
From: David Bertoni [dbertoni@apache.org]
Sent: Wednesday, August 01, 2007 9:00 AM
To: xalan-dev@xml.apache.org
Subject: Re: Xalan (with Xerces) - Modify a value at a Node

Vikram A K Gupta wrote:
> Hi All,
>
> Background
> - We are developing a generic cross reference task for a middleware application.
> - We will be processing multiple XML formats and the plan is to have a single instance of the new cross reference task.
> - We plan on configuring XPATH rules to extract a value (extraction is processed by another task and is complete)
> - After obtaining the value from the XML, we will do a cross reference look-up via a database and then look to repopulate the new value back in the msg via the original XPATH rule,
>
> The issue we are having is around the re-insertion of the value.
> Approach that we are using:
>                1) XercesLiaisonParser to parse message
>                2) XPathEvaluator to identify a particular node
>                3) XalanNode::setNodeValue to modify the value
> But we are getting 'Unknown exception' when i try to do XalanNode::setNodeValue. Any pointers to resolve it ?
> Following is code snippet but it is failing with the UNKNOWN EXCEPTION
It should not an "unknown" exception, it should be a XalanDOMException.
Here's a snippet from the source code:

void
XalanSourceTreeElement::setNodeValue(const XalanDOMString&              /* nodeValue */)
{
        throw XalanDOMException(XalanDOMException::NO_MODIFICATION_ALLOWED_ERR);
}

>
> Any clue how to resolve it and also an alternative approach to achieve the requirement !!
>
> try{
>
>     // We'll use these to parse the XML file.
>     XercesDOMSupport theDOMSupport;
>     XercesParserLiaison theLiaison(theDOMSupport);
>
>     // Create an input source...
>     const MemBufInputSource theInputSource( reinterpret_cast<const XMLByte*>(message.c_str()),
>     XalanDOMString::length(message.c_str()),
>     "SourceXML",
>     false );
>
>     // Parse the XML Stream
>     XalanDocument* const theDocument = theLiaison.parseXMLStream(theInputSource);
>     XPathEvaluator      theEvaluator;
>     XalanNode* const theContextNode = theDocument->getDocumentElement();
>
>     //Retrieve the XalanNode for the compiled XPath
>     XalanNode* pXalanNode, *pConstNode = NULL;
>     pConstNode =  theEvaluator.selectSingleNode (theDOMSupport,
>     theContextNode,
>     *m_compiledXPATH);
>
>     XalanDOMString xalanDOMString("NewValue");
>     pConstNode->setNodeValue(xalanDOMString);    // UNKNOWN EXCEPTION BEING THROWN
>
>     }
>     catch(const XalanDOMException& xde)
>     {
>     }
>     catch(const DOMException& de)
>     {
>     }
>     catch (...) // UNKNOWN EXCEPTION BEING CAUGHT HERE
>     {
>     }
Unless the node is a null pointer, and you're not checking for that, I
don't know why you're getting an unknown exception.  Often, running your
code in a debugger will help with determining what's wrong.

However, your approach will not work, as the Xalan-C source tree is not
mutable.  The typical way to handle this is to either use the Xerces-C
source tree with the Xalan-C wrappers, or write an XSLT stylesheet that
does the transformation, changing the values as appropriate.

Dave

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org


**************** 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: xalan-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-dev-help@xml.apache.org