How to update a XML-file from itself?
Friday, 8 August 2014 · 5 messages
RS
Rob Stapper8 Aug 2014 15:49 #
Hi,
Can anyone help me with this casus?
I want to update XML-source: $a, by inserting the content of XML-element:
$b, a sub-element of $a, into XML-element: $c, also a sub-element of $a.The relative path from $b to $c is known.
See attached example: the problem is that the update works on a copy of $a
and that the destination-element: $b/parent::*/default/text1, is actually an
element of the original $a.How can I make it point to the corresponding element in the copy?
Any suggestions?
Thanx in advance,
Rob Stapper
---
Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus-bescherming actief is. http://www.avast.com
CG
Christian Grün8 Aug 2014 16:03 #
Hi Rob,
I didn't find variable $c in your example, but the following modification might give you the correct result:
let $update.processor := function($a, $b) {
($a update replace value of node ./default/text1 with ())
update insert node $b/string into .//default/text1
}...or (depending on what you plan to do):
let $update.processor := function($a, $b) {
($a update insert node $b/string into default/text1)
}As you already observed, it is only possible to update nodes that have been copied by the 'update' keyword.
Hope this helps,
Christian
Quoted text · Rob Stapper · 42 lines
On Fri, Aug 8, 2014 at 3:49 PM, Rob Stapper <r.stapper at lijbrandt.nl> wrote: > Hi, > > > > Can anyone help me with this casus? > > > > I want to update XML-source: $a, by inserting the content of XML-element: > $b, a sub-element of $a, into XML-element: $c, also a sub-element of $a. > > The relative path from $b to $c is known. > > > > See attached example: the problem is that the update works on a copy of $a > and that the destination-element: $b/parent::*/default/text1, is actually > an element of the original $a. > > How can I make it point to the corresponding element in the copy? > > > > Any suggestions? > > > > Thanx in advance, > > > > Rob Stapper > > > ------------------------------ > <http://www.avast.com/> > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus > <http://www.avast.com/> actief is. > >
RS
Rob Stapper8 Aug 2014 16:26 #
Hi Christian,
Thanx for the ultra fast response.
The problem is that my actual program I dont know the path from the root
of $a to default/text1 ( $c), in this case: ./. Element:
default/text1 ( $c), could be located anywhere in $a.
I do know the relative path to default/text1 from $b, in this case:
$b/parent::*/default/text1.Its not that simple;-) ( not to me anyway)
Any other suggestions?
Rob
PS Ive tried it with soring the XML in the database and using node-id(). But apparently the copy doesnt use node-ids. So this didnt work.
Quoted text · Christian Grün · 40 lines
Van: Christian Grün [mailto:christian.gruen at gmail.com] Verzonden: vrijdag 8 augustus 2014 16:04 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] How to update a XML-file from itself? Hi Rob, I didnt find variable $c in your example, but the following modification might give you the correct result: let $update.processor := function($a, $b) { ($a update replace value of node ./default/text1 with ()) update insert node $b/string into .//default/text1 } or (depending on what you plan to do): let $update.processor := function($a, $b) { ($a update insert node $b/string into default/text1) } As you already observed, it is only possible to update nodes that have been copied by the 'update' keyword. Hope this helps, Christian On Fri, Aug 8, 2014 at 3:49 PM, Rob Stapper <r.stapper at lijbrandt.nl> wrote: Hi, Can anyone help me with this casus? I want to update XML-source: $a, by inserting the content of XML-element: $b, a sub-element of $a, into XML-element: $c, also a sub-element of $a. The relative path from $b to $c is known. See attached example: the problem is that the update works on a copy of $a and that the destination-element: $b/parent::*/default/text1, is actually an element of the original $a. How can I make it point to the corresponding element in the copy? Any suggestions? Thanx in advance, Rob Stapper _____ <http://www.avast.com/> Afbeelding verwijderd door afzender. Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus <http://www.avast.com/> actief is. --- Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus-bescherming actief is. http://www.avast.com
RS
Hi,
Here is another thingy I tried but again: no cigar.
The problem would be solved if I could determine the absolute path to an element-variable: $c
Rob
Quoted text · Christian Grün · 40 lines
Van: Christian Grün [mailto:christian.gruen at gmail.com] Verzonden: vrijdag 8 augustus 2014 16:04 Aan: Rob Stapper CC: BaseX Onderwerp: Re: [basex-talk] How to update a XML-file from itself? Hi Rob, I didnt find variable $c in your example, but the following modification might give you the correct result: let $update.processor := function($a, $b) { ($a update replace value of node ./default/text1 with ()) update insert node $b/string into .//default/text1 } or (depending on what you plan to do): let $update.processor := function($a, $b) { ($a update insert node $b/string into default/text1) } As you already observed, it is only possible to update nodes that have been copied by the 'update' keyword. Hope this helps, Christian On Fri, Aug 8, 2014 at 3:49 PM, Rob Stapper <r.stapper at lijbrandt.nl> wrote: Hi, Can anyone help me with this casus? I want to update XML-source: $a, by inserting the content of XML-element: $b, a sub-element of $a, into XML-element: $c, also a sub-element of $a. The relative path from $b to $c is known. See attached example: the problem is that the update works on a copy of $a and that the destination-element: $b/parent::*/default/text1, is actually an element of the original $a. How can I make it point to the corresponding element in the copy? Any suggestions? Thanx in advance, Rob Stapper _____ <http://www.avast.com/> Afbeelding verwijderd door afzender. Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus <http://www.avast.com/> actief is. --- Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus-bescherming actief is. http://www.avast.com
CG
Quoted text · Rob Stapper · 1 line
>
Any other suggestions?
Hm, no easy one. You could pass on a function that does the navigation to the relevant nodes:
let $f := function($node) { $node/update1 }
return $a update replace value of node $f(.) with "bla"Christian
Quoted text · Rob Stapper · 143 lines
On Fri, Aug 8, 2014 at 4:26 PM, Rob Stapper <r.stapper at lijbrandt.nl> wrote: > Hi Christian, > > > > Thanx for the ultra fast response. > > > > The problem is that my actual program I don't know the path from the root > of $a to "default/text1" ( $c), in this case: "./". Element: > "default/text1" ( $c), could be located anywhere in $a. > > I do know the relative path to "default/text1" from $b, in this case: > "$b/parent::*/default/text1". > > > > It's not that simple;-) ( not to me anyway) > > > > Rob > > > > PS I've tried it with soring the XML in the database and using node-id(). > But apparently the copy doesn't use node-id's. So this didn't work. > > > > > > *Van:* Christian Grün [mailto:christian.gruen at gmail.com] > *Verzonden:* vrijdag 8 augustus 2014 16:04 > *Aan:* Rob Stapper > *CC:* BaseX > *Onderwerp:* Re: [basex-talk] How to update a XML-file from itself? > > > > Hi Rob, > > > > I didn't find variable $c in your example, but the following modification > might give you the correct result: > > > > let $update.processor := function($a, $b) { > > ($a update replace value of node ./default/text1 with ()) > > update insert node $b/string into .//default/text1 > > } > > > > ...or (depending on what you plan to do): > > > > let $update.processor := function($a, $b) { > > ($a update insert node $b/string into default/text1) > > } > > > > As you already observed, it is only possible to update nodes that have > been copied by the 'update' keyword. > > > > Hope this helps, > > Christian > > > > > > > > On Fri, Aug 8, 2014 at 3:49 PM, Rob Stapper <r.stapper at lijbrandt.nl> > wrote: > > Hi, > > > > Can anyone help me with this casus? > > > > I want to update XML-source: $a, by inserting the content of XML-element: > $b, a sub-element of $a, into XML-element: $c, also a sub-element of $a. > > The relative path from $b to $c is known. > > > > See attached example: the problem is that the update works on a copy of $a > and that the destination-element: $b/parent::*/default/text1, is actually > an element of the original $a. > > How can I make it point to the corresponding element in the copy? > > > > Any suggestions? > > > > Thanx in advance, > > > > Rob Stapper > > > ------------------------------ > > [image: Afbeelding verwijderd door afzender.] <http://www.avast.com/> > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus > <http://www.avast.com/> actief is. > > > > > > > ------------------------------ > <http://www.avast.com/> > > Dit e-mailbericht bevat geen virussen en malware omdat avast! Antivirus > <http://www.avast.com/> actief is. > >
Written for BaseX 7.9. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery