XQuery to insert nodes in XML File
Friday, 14 June 2013 · 3 messages
JB
John Best14 Jun 2013 10:29 #
Dear Team,
I am trying to insert few nodes in a XML File. But in reality the nodes are not inserting in the XML File!!
Below is my query
for $x in doc('C:\sample.xml')//CInfos
return insert node <Info><Name>James
Stuart</Name><Key>7709422869</Key></Info> as last into $xI tried with another query -
insert node <Info>
<Name>James Stuart</Name>
<Key>7709422869</Key>
</Info> as last into doc('C:\sample.xml')//CInfosThis too not working
If I create a XML DB and then it works...
What am I missing?
--
Have a nice day
JBest
DK
Dirk Kirsten14 Jun 2013 10:35 #
Hello John,
All updates in BaseX are performed on database nodes or in main memory as specified by the XQuery Update spec. You are trying to update a document in the filesystem.
You can update thr document in main mamory and afterwards store it using the
fn:put function (see
http://www.w3.org/TR/xquery-update-10/#id-func-put).
Cheers,
DirkQuoted text · John Best · 37 lines
On 06/14/2013 10:29 AM, John Best wrote: > Dear Team, > > > I am trying to insert few nodes in a XML File. But in reality the nodes > are not inserting in the XML File!! > > Below is my query > > for $x in doc('C:\sample.xml')//CInfos > return insert node <Info><Name>James > Stuart</Name><Key>7709422869</Key></Info> as last into $x > > I tried with another query - > > insert node <Info> > <Name>James Stuart</Name> > <Key>7709422869</Key> > </Info> as last into doc('C:\sample.xml')//CInfos > > This too not working > > If I create a XML DB and then it works... > What am I missing? > > -- > Have a nice day > JBest > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
--
Dirk Kirsten, BaseX GmbH, http://basex.org
|-- Firmensitz: Blarerstrasse 56, 78462 Konstanz
|-- Registergericht Freiburg, HRB: 708285, Geschäftsführer:
| Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
CG
Christian Grün14 Jun 2013 11:39 #
Hi John,
there is one (pretty unknown) option called
WRITEBACK [1], which can also be activated via -u on command line [2]; it ensures that changes will be written back to the original file.
Best,
Christian
[1] http://docs.basex.org/wiki/Options#WRITEBACK
[2] http://docs.basex.org/wiki/Startup_Options#BaseX_StandaloneQuoted text · Dirk Kirsten · 61 lines
> Hello John, > > All updates in BaseX are performed on database nodes or in main memory as > specified by the XQuery Update spec. You are trying to update a document in > the filesystem. > You can update thr document in main mamory and afterwards store it using the > fn:put function (see http://www.w3.org/TR/xquery-update-10/#id-func-put). > > Cheers, > Dirk > > > On 06/14/2013 10:29 AM, John Best wrote: >> >> Dear Team, >> >> >> I am trying to insert few nodes in a XML File. But in reality the nodes >> are not inserting in the XML File!! >> >> Below is my query >> >> for $x in doc('C:\sample.xml')//CInfos >> return insert node <Info><Name>James >> Stuart</Name><Key>7709422869</Key></Info> as last into $x >> >> I tried with another query - >> >> insert node <Info> >> <Name>James Stuart</Name> >> <Key>7709422869</Key> >> </Info> as last into doc('C:\sample.xml')//CInfos >> >> This too not working >> >> If I create a XML DB and then it works... >> What am I missing? >> >> -- >> Have a nice day >> JBest >> >> >> >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >> > > -- > Dirk Kirsten, BaseX GmbH, http://basex.org > |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz > |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: > | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle > `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22 > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Written for BaseX 7.6. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery