Insert a node in in-memory nodes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Insert a node in in-memory nodes

Felix Maas
Hello everyone,
 
I am creating a web-based database application with eXist-db.
My wish is to save the data the user inserts in a formular created with XForms into the database. For that the whole data structure is saved in the variable $content I store in the database with an XQuery module like that:
 
declare
    %rest:PUT("{$content}")
    %rest:path("/items")
function ffdb:change:items($content as node()*) {
    let $data := <items>
            { $content/items/* }
        </items>
    let $stored := xmldb:store($config:app-root, "1234.xml", $data)
    
    return
        doesnotmatter:function()
};
 
 
In this example $content contains the following nodeset:
 
<items>
    <item1>A</item>
    <item2>B</item>
    <itemlist>
        <item3>C</item3>
    <itemlist/>
<items>

That works fine. My problem is that I want to insert a node <item3> with the content 'D' in $content/items/itemlist before it is stored into the database. The result should be:
 
<items>
    <item1>A</item>
    <item2>B</item>
    <itemlist>
        <item3>C</item3>
        <item3>D</item3>
    <itemlist/>
<items>
 
That seems to be more difficult as I thought. I tried to change the query a hundred times I think.
When I try to insert a nodeset directly in the $content I get the message that XQuery update expressions can not be applied to in-memory nodes.
When I try to insert the nodeset in $data after declaring it the data is stored but unfortunately without the nodeset.
I also installed the module from https://github.com/ryanjdew/XQuery-XML-Memory-Operations and then inserted this at the beginning:
 
    let $content2 := mem:copy($content) !
        (
        mem:insert-child(., $content/items/itemlist, attribute new-attribute {"item3"}),
        mem:execute(.))
 
After that I inserted $content2 instead of $content while declaring $data. The message I get is the following:
org.exist.xquery.XPathException: mem-op:MIXEDSOURCES The nodes to change are coming from multiple sources [at line 249, column 3, source: /db/apps/ffdb/modules/memoryoperations/memory-operations-pure-xquery.xqy]
Do not really know what to do. I also tried to load the document after storing it and insert the nodeset here so that I do not change in-memory data but that also does not work. The nodeset is not been inserted.
 
    let $stored := xmldb:store($config:app-root, "1234.xml", $data)
    
    let $data2 := doc(concat($config:app-root, "1234.xml"))
    let $insertnode := update insert <item3>D</item3> into $data2/items/itemlist
 
Hope you can help me.
 
Best regards,
Felix

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Insert a node in in-memory nodes

Joe Wicentowski
Felix,

I'm a little puzzled by your question, since it covers ground in a
question you asked on Stack Overflow that I answered - and that you
confirmed answered your question:

  http://stackoverflow.com/questions/42813532/exist-db-xquery-update-in-memory-nodes-before-storing-the-data

Joe

On Wed, Mar 15, 2017 at 11:16 AM, Felix Maas <[hidden email]> wrote:

> Hello everyone,
>
> I am creating a web-based database application with eXist-db.
> My wish is to save the data the user inserts in a formular created with
> XForms into the database. For that the whole data structure is saved in the
> variable $content I store in the database with an XQuery module like that:
>
> declare
>     %rest:PUT("{$content}")
>     %rest:path("/items")
> function ffdb:change:items($content as node()*) {
>     let $data := <items>
>             { $content/items/* }
>         </items>
>     let $stored := xmldb:store($config:app-root, "1234.xml", $data)
>
>     return
>         doesnotmatter:function()
> };
>
>
> In this example $content contains the following nodeset:
>
> <items>
>     <item1>A</item>
>     <item2>B</item>
>     <itemlist>
>         <item3>C</item3>
>     <itemlist/>
> <items>
>
> That works fine. My problem is that I want to insert a node <item3> with the
> content 'D' in $content/items/itemlist before it is stored into the
> database. The result should be:
>
> <items>
>     <item1>A</item>
>     <item2>B</item>
>     <itemlist>
>         <item3>C</item3>
>         <item3>D</item3>
>     <itemlist/>
> <items>
>
> That seems to be more difficult as I thought. I tried to change the query a
> hundred times I think.
> When I try to insert a nodeset directly in the $content I get the message
> that XQuery update expressions can not be applied to in-memory nodes.
> When I try to insert the nodeset in $data after declaring it the data is
> stored but unfortunately without the nodeset.
> I also installed the module from
> https://github.com/ryanjdew/XQuery-XML-Memory-Operations and then inserted
> this at the beginning:
>
>     let $content2 := mem:copy($content) !
>         (
>         mem:insert-child(., $content/items/itemlist, attribute new-attribute
> {"item3"}),
>         mem:execute(.))
>
> After that I inserted $content2 instead of $content while declaring $data.
> The message I get is the following:
> org.exist.xquery.XPathException: mem-op:MIXEDSOURCES The nodes to change are
> coming from multiple sources [at line 249, column 3, source:
> /db/apps/ffdb/modules/memoryoperations/memory-operations-pure-xquery.xqy]
> Do not really know what to do. I also tried to load the document after
> storing it and insert the nodeset here so that I do not change in-memory
> data but that also does not work. The nodeset is not been inserted.
>
>     let $stored := xmldb:store($config:app-root, "1234.xml", $data)
>
>     let $data2 := doc(concat($config:app-root, "1234.xml"))
>     let $insertnode := update insert <item3>D</item3> into
> $data2/items/itemlist
>
> Hope you can help me.
>
> Best regards,
> Felix
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Exist-open mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/exist-open
>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Insert a node in in-memory nodes

Joe Wicentowski
Hi Felix,

Ah, I see, your email was sent *4 days ago* on March 15 - the same day
you asked the question on Stackoverflow.  I see your other two
questions that also appeared on exist-open at the same moment were
also answered on Stackoverflow.  So if you have any outstanding
questions, please let us know.

But in the future, to avoid duplication of community efforts, please
post eXist questions to either stackoverflow or exist-open, not both.
More of the eXist community is here - so now that you've found us I
think you'll find exist-open a better place to seek advice.  At the
same time, I don't know what could've held up your email for this many
days, so until we're sure what's going on (plenty of people have
posted to exist-open, so ??), perhaps stackoverflow is the better
option.

Joe

On Sun, Mar 19, 2017 at 8:07 PM, Joe Wicentowski <[hidden email]> wrote:

> Felix,
>
> I'm a little puzzled by your question, since it covers ground in a
> question you asked on Stack Overflow that I answered - and that you
> confirmed answered your question:
>
>   http://stackoverflow.com/questions/42813532/exist-db-xquery-update-in-memory-nodes-before-storing-the-data
>
> Joe
>
> On Wed, Mar 15, 2017 at 11:16 AM, Felix Maas <[hidden email]> wrote:
>> Hello everyone,
>>
>> I am creating a web-based database application with eXist-db.
>> My wish is to save the data the user inserts in a formular created with
>> XForms into the database. For that the whole data structure is saved in the
>> variable $content I store in the database with an XQuery module like that:
>>
>> declare
>>     %rest:PUT("{$content}")
>>     %rest:path("/items")
>> function ffdb:change:items($content as node()*) {
>>     let $data := <items>
>>             { $content/items/* }
>>         </items>
>>     let $stored := xmldb:store($config:app-root, "1234.xml", $data)
>>
>>     return
>>         doesnotmatter:function()
>> };
>>
>>
>> In this example $content contains the following nodeset:
>>
>> <items>
>>     <item1>A</item>
>>     <item2>B</item>
>>     <itemlist>
>>         <item3>C</item3>
>>     <itemlist/>
>> <items>
>>
>> That works fine. My problem is that I want to insert a node <item3> with the
>> content 'D' in $content/items/itemlist before it is stored into the
>> database. The result should be:
>>
>> <items>
>>     <item1>A</item>
>>     <item2>B</item>
>>     <itemlist>
>>         <item3>C</item3>
>>         <item3>D</item3>
>>     <itemlist/>
>> <items>
>>
>> That seems to be more difficult as I thought. I tried to change the query a
>> hundred times I think.
>> When I try to insert a nodeset directly in the $content I get the message
>> that XQuery update expressions can not be applied to in-memory nodes.
>> When I try to insert the nodeset in $data after declaring it the data is
>> stored but unfortunately without the nodeset.
>> I also installed the module from
>> https://github.com/ryanjdew/XQuery-XML-Memory-Operations and then inserted
>> this at the beginning:
>>
>>     let $content2 := mem:copy($content) !
>>         (
>>         mem:insert-child(., $content/items/itemlist, attribute new-attribute
>> {"item3"}),
>>         mem:execute(.))
>>
>> After that I inserted $content2 instead of $content while declaring $data.
>> The message I get is the following:
>> org.exist.xquery.XPathException: mem-op:MIXEDSOURCES The nodes to change are
>> coming from multiple sources [at line 249, column 3, source:
>> /db/apps/ffdb/modules/memoryoperations/memory-operations-pure-xquery.xqy]
>> Do not really know what to do. I also tried to load the document after
>> storing it and insert the nodeset here so that I do not change in-memory
>> data but that also does not work. The nodeset is not been inserted.
>>
>>     let $stored := xmldb:store($config:app-root, "1234.xml", $data)
>>
>>     let $data2 := doc(concat($config:app-root, "1234.xml"))
>>     let $insertnode := update insert <item3>D</item3> into
>> $data2/items/itemlist
>>
>> Hope you can help me.
>>
>> Best regards,
>> Felix
>>
>> ------------------------------------------------------------------------------
>> Check out the vibrant tech community on one of the world's most
>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>> _______________________________________________
>> Exist-open mailing list
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/exist-open
>>

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open
Loading...