storing xml-elements
Saturday, 25 May 2024 · 3 messages · last reply 27 May 2024
RS
Rob Stapper25 May 2024 08:45 #
Hi Christian,
I'm looking for a way to store a xml-subelement during a session as a subelement and not as a rootelement. The store- and the session:set-function save xml-elements as a root-elements, loosing the origional root.
My casus is that I have this batch-webservice that I want to turn into a online/interactive-webservice. The application makes use of the root- and ancestor functions/axis on xml-subelements. In the batch solution I have access to the origional xml-subelement. In the online-solution however I have not. This because the code is broken up due to a http-request/response interaction with the user. I would like the xml-subelement to survive this http-excursion in a way that its root-element stays available and the root- and ancestor-function gives the same result as in the batch-version.
Do you have any suggestions on this?
mvgr.
Rob Stapper
CG
Christian Grün27 May 2024 12:41 #
Hi Rob,
I think there are various way to achieve that. One way is to store both the full document in the session as well as the path to the requested node:
let $xml := <data><bla><blu/></bla></data>
let $result := $xml//blu
let $path := path($result)
return (
session:set('xml', $xml),
session:set('xml', $path)
)You can run a dynamic query on the XML snippet to get back your original result:
let $xml := session:get('xml')
let $path := session:get('path')
let $result := xquery:eval($path, { '': $xml })
return $resultBest,
Christian
Quoted text · Rob Stapper · 25 lines
On Sat, May 25, 2024 at 8:45 AM Rob Stapper <r.stapper at lijbrandt.nl> wrote: > Hi Christian, > > I'm looking for a way to store a xml-subelement during a session as a > subelement and not as a rootelement. The store- and the > session:set-function save xml-elements as a root-elements, loosing the > origional root. > > My casus is that I have this batch-webservice that I want to turn into a > online/interactive-webservice. The application makes use of the root- and > ancestor functions/axis on xml-subelements. In the batch solution I have > access to the origional xml-subelement. In the online-solution however I > have not. This because the code is broken up due to a http-request/response > interaction with the user. I would like the xml-subelement to survive this > http-excursion in a way that its root-element stays available and the root- > and ancestor-function gives the same result as in the batch-version. > > Do you have any suggestions on this? > > > mvgr. > > Rob Stapper > >
RS
Rob Stapper27 May 2024 14:07 #
Christian,
Thnx for the reply. I also thought of this approach. Probably the best way to go.
Rob
Quoted text · Christian Grün · 44 lines
> Op 27-05-2024 12:41 CEST schreef Christian Grün <christian.gruen at gmail.com>: > > > Hi Rob, > > I think there are various way to achieve that. One way is to store both the full document in the session as well as the path to the requested node: > > let $xml := <data><bla><blu/></bla></data> > let $result := $xml//blu > let $path := path($result) > return ( > session:set('xml', $xml), > session:set('xml', $path) > ) > > You can run a dynamic query on the XML snippet to get back your original result: > > let $xml := session:get('xml') > let $path := session:get('path') > let $result := xquery:eval($path, { '': $xml }) > return $result > > Best, > Christian > > > > On Sat, May 25, 2024 at 8:45 AM Rob Stapper <r.stapper at lijbrandt.nl mailto:r.stapper at lijbrandt.nl> wrote: > > > Hi Christian, > > > > I'm looking for a way to store a xml-subelement during a session as a subelement and not as a rootelement. The store- and the session:set-function save xml-elements as a root-elements, loosing the origional root. > > > > My casus is that I have this batch-webservice that I want to turn into a online/interactive-webservice. The application makes use of the root- and ancestor functions/axis on xml-subelements. In the batch solution I have access to the origional xml-subelement. In the online-solution however I have not. This because the code is broken up due to a http-request/response interaction with the user. I would like the xml-subelement to survive this http-excursion in a way that its root-element stays available and the root- and ancestor-function gives the same result as in the batch-version. > > > > Do you have any suggestions on this? > > > > > > mvgr. > > > > Rob Stapper > > > >
mvgr.
Rob Stapper
Written for BaseX 10.7. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery