If you look at the documentation for XercesParserLiaison, you will see the
following member function:
/**
* Create a XalanDocument proxy for an existing Xerces document.
* The parser liaison owns the instance, and you must not delete
* it. The liaison will delete it when reset() is called, or the
* liaison is destroyed.
*
* @param theXercesDocument The Xerces document.
* @param threadSafe If true, read access to the tree will be
thread-safe (implies buildWrapper == true).
* @param buildWrapper If true, the entire wrapper structure is
built.
* @param buildMaps If true, the map of Xerces to Xalan nodes is
always built.
* @return a pointer to a new XalanDocument-derived instance.
*/
XalanDocument*
createDocument(
const DOMDocument_Type* theXercesDocument,
bool threadSafe,
bool buildWrapper,
bool buildMaps = false);
Dave
|---------+--------------------------->
| | "Liu, Richard" |
| | <[EMAIL PROTECTED]|
| | ing.com> |
| | |
| | 03/02/2004 03:42|
| | PM |
| | Please respond |
| | to xalan-c-users|
|---------+--------------------------->
>-------------------------------------------------------------------------------------------------------------------------------|
|
|
| To: <[email protected]>, <[EMAIL PROTECTED]>
|
| cc: (bcc: David N Bertoni/Cambridge/IBM)
|
| Subject: RE: Do we have any way to update or change the value of of
a DOMTREE in the memory using xpath and Xalan |
| libiary ?
|
>-------------------------------------------------------------------------------------------------------------------------------|
Hi, Erik:
Thank you for your answer.
However, I still have some trouble to make it work.
My major trouble is how can I get the correct XercesDocumentWrapper
constructed ? The XercesDocumentWrapper takes a DomDocument as the first
parameter, I get the DomDocument in the following way (I do not know if
this is correct).
XalanDOMString * theFileName = new XalanDOMString
(yourFilePath.c_str());
LocalFileInputSource * myTmpInputSource = new LocalFileInputSource
((*theFileName).c_str());
XercesParserLiaison::DOMParserType theParser;
theParser.parse( *myTmpInputSource);
DOMDocument * XercesDocument = theParser.getDocument(); //Here is the
way to get the DOMDocument, is this O.K ?
XercesDocumentWrapper theWrapper (XercesDocument);
//After I got XalanNode * theNode using some other way (using
theEavluate.selectSingleNode and slectNodeList). I called the following
function
//
DOMNode * xercesNode = (DOMNode* ) theWrapper.mapNode (theNode);
But as soon as the above sentence called, it goes to the catch exception
block. I am not sure what's going wrong.
By the way, do you have any code sample to show the answer you shown me
in your last E-mail ? It will be very helpful
I can see the code sample.
Thanks a lot for your help.
Sincerely
Richard Liu
Software Engineer at Boeing
-----Original Message-----
From: Erik Rydgren [mailto:[EMAIL PROTECTED]
Sent: Monday, March 01, 2004 10:12 AM
To: [email protected]
Subject: RE: Do we have any way to update or change the value of of a
DOMTREE in the memory using xpath and Xalan libiary ?
Xalan can do it. You simply select the nodes you are interested in with
XPath and loop over the result while applying your changes.
(Warning: The following code is written on top of my head and may
contain errors or cause confusion)
For instance assume that you have this document in memory:
<doc>
<wanteditem attr="value1"/>
<notwanteditem attr="somevalue"/>
<wanteditem attr="value2"/>
</doc>
Then assume that you want to change all /doc/wanteditem/@attr value to
foobar.
- First select your nodes with Xalan XPath using a XercesDocumentWrapper
and XPath evaluator. (xpath: /doc/wanteditem/@attr)
You will get a XObject that is a nodeset of 2 attribute nodes.
- Extract the nodeset object from the XObject. (Method on the XObject)
- Loop through the nodeset getting XalanNode pointers.
- The Xalan nodes are read only so you need to map the XalanNodes to
XercesNodes. This is done with the XercesDocumentWrapper::map method.
- You will then have the node that corresponds to the attr. Do a
setNodeValue to "foobar".
- Repeat for each node in the nodeset and you are done.
Remember to rebuild the XercesDocumentWrapper between changes in the
document.
/ Erik
> -----Original Message-----
> From: Liu, Richard [mailto:[EMAIL PROTECTED]
> Sent: den 1 mars 2004 15:54
> To: [email protected]
> Subject: Do we have any way to update or change the value of of a
DOMTREE
> in the memory using xpath and Xalan libiary ?
>
> Hi,
>
> I have a general question in terms of xpath ability.
>
> I know we can extract (get) the specific value of a node using xPath
> query.
>
> However, our application needs to have the ability to change or
update
> the value of certain nodes, I have no idea if we can do it?
> If using xPath and Xalan library can not do it, do we have any other
> tools that may support this ability ?
>
>
> Thanks
>
> Richard Liu
> Software Engineer at Boeing
>
>