Re: [bdbxml] Replacing and inserting nodes

George Feinberg <[email protected]>
Newsgroups gmane.comp.db.dbxml.general
Message-ID <[email protected]>
> while searching for a free XML database for my diploma thesis, I  
> came across
> bdbxml, which I like a lot. However I am missing a certain  
> behaviour with
> respect to updating and creating nodes in a document.
>
> I am using the Java API and the class in question is of course  
> XmlModify. What
> I need to do is the following:
>
> In a document, locate a specific node and then replace that node  
> with content
> I have as a String. For example I have the following document:
>
> <foo>
>     <bar value="1">
>         data
>     </bar>
>     <bar value="2">
>         moredata
>     </bar>
> </foo>
>
> Now I want to replace the node specified by the XPath
> Query /foo/bar[@value="1"] with the following node:
>
> <bar value="15">
>     randomdata
> </bar>
>
> It seems that there is no method of XmlModify which elegantly  
> handles such a
> situation. It only allows for modification of node contens with
> addUpdateStep. Even the insert methods are not satisfactory for  
> that example,
> because they can't take the whole String as a new node, but require  
> creation
> of an additional node by specifying name and node Type.
>
> Am I missing somethig or do I really need to do something like this:

The former :-)

XmlModify works by adding "steps," and then executing the object.
Each step takes an XmlQueryExpression along with some step-specific
parameters.

In your case, you simply need 2 update steps, one that targets the  
element
to change the content from "data" to "randomdata" and one to
change the attribute, "value" from "1" to "15".

The pseudo-code is along these lines:
     XmlQueryExpression qe1 = mgr.prepare("/foo/bar[@value='1']", qc);
     XmlQueryExpression qe2 = mgr.prepare("/foo/bar[@value='1']/ 
@value", qc);

     XmlModify mod = mgr.createModify();
     mod.addUpdateStep(qe1, "randomdata");
     mod.addUpdateStep(qe2, "15");
     mod.execute(...)

Regards,

George

>
> 1) Strip the root from the string to insert
> 2) insert a new node, with type = element, name = name of the  
> stripped node
> and content of the remaining insert string
> 3) remove the node I wanted to replace.
>
> I hope my explanations are not too confusing ;-)
>
> Regards,
> Sebastian
>


------------------------------------------
To remove yourself from this list, send an
email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.