Problem when using insert or replace

Monday, 12 May 2014 · 2 messages · last reply 13 May 2014
M
Mike12 May 2014 21:41 #

Hi all,

I am new with BaseX, and I'm trying to learn how to insert and replace nodes in my xml database, but when I run a script, the Result window don't show any changes.

If I export the DB, nothing seems to be updated.

But the Query Info don't show any error.

The scripts I'm using are:

To insert:

insert node
	<titular nif="73890234K">
		<nombre>Pobre Cico, Daniel</nombre>
		<domicilio>C/Del Esmirriao, 23-1</domicilio>
		<codigo_postal>46900</codigo_postal>
		<poblacion>Benimacarrón</poblacion>
		<provincia>Valencia</provincia>
	</titular>
as first into doc("titulares.xml")//titulares

To replace:

replace value of node doc("titulares.xml")//titulares/titular[@nif="83709245Y"]/codigo_pos tal with "46999"

The Query Info shows:

Result: - Hit(s): 0 Items - Updated: 3 Items - Printed: 0 Bytes - Read Locking: none - Write Locking: global

My xml DB is:

<titulares>
	<titular nif="83709245Y">
		<nombre>Rica Chon, Esteban</nombre>
		<domicilio>Avda. de la Plata, 32</domicilio>
		<codigo_postal>46023</codigo_postal>
		<poblacion>Valencia</poblacion>
		<provincia>Valencia</provincia>
	</titular>
	<titular nif="83845902R">
		<nombre>Forrao Bucho, Joaquín</nombre>
		<domicilio>Plaza del Oro, 45</domicilio>
		<codigo_postal>44000</codigo_postal>
		<poblacion>La Mina</poblacion>
		<provincia>Albacete</provincia>
	</titular>

etc.

Any help will be very appreciated.

Thanks!

CG
Christian Grün13 May 2014 00:11 #

Hi Mike,

you may need to address your database via db:open("titulares"):

insert node <titular nif="73890234K"> ... </titular> as first into db:open("titulares")//titulares

Otherwise, the node will be inserted into the original document (but not saved back to disk, as this would first need to be activated via the WRITEBACK option [1]).

Hope this helps, Christian

[1] http://docs.basex.org/wiki/Options#WRITEBACK

Quoted text · Mike · 54 lines
> insert node > <titular nif="73890234K"> > <nombre>Pobre Cico, Daniel</nombre> > <domicilio>C/Del Esmirriao, 23-1</domicilio> > <codigo_postal>46900</codigo_postal> > <poblacion>Benimacarrón</poblacion> > <provincia>Valencia</provincia> > </titular> > as first into doc("titulares.xml")//titulares > > To replace: > > replace value of node > doc("titulares.xml")//titulares/titular[@nif="83709245Y"]/codigo_pos > tal > with > "46999" > > The Query Info shows: > > Result: > - Hit(s): 0 Items > - Updated: 3 Items > - Printed: 0 Bytes > - Read Locking: none > - Write Locking: global > > My xml DB is: > > <titulares> > <titular nif="83709245Y"> > <nombre>Rica Chon, Esteban</nombre> > <domicilio>Avda. de la Plata, 32</domicilio> > <codigo_postal>46023</codigo_postal> > <poblacion>Valencia</poblacion> > <provincia>Valencia</provincia> > </titular> > <titular nif="83845902R"> > <nombre>Forrao Bucho, Joaquín</nombre> > <domicilio>Plaza del Oro, 45</domicilio> > <codigo_postal>44000</codigo_postal> > <poblacion>La Mina</poblacion> > <provincia>Albacete</provincia> > </titular> > > etc. > > Any help will be very appreciated. > > Thanks! > > > >

⚡Generated with XQuery