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
> 
> 

Reply via email to