Writing updates to xml file with XQuery and BaseX -
i have file.xml storing protocols structure following:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <economato> <protocollo> <numero>1</numero> <data>2014-12-15</data> <oggetto>trasmissione prospetti di rendiconto chiusura esercizio 2012 - beni mobili proprietà dello stato</oggetto> <destinatario>ragioneria provinciale como</destinatario> <operatore>maestri</operatore> <valido>true</valido> </protocollo> ... </economato>
and need change/update value of tag "valido", example 'true' 'false' of protocollo number 1 , update written file. using basex, following documentation have tried write query:
xquery let $update := doc('c:\users\lorenzo enzino vinci\desktop\economato\databases\2014.xml')//economato/protocollo[numero = 1] return replace value of node $update/valido 'false' doc('c:\users\lorenzo enzino vinci\desktop\economato\databases\2014.xml')//economato
but error
[xpst0003] unexpected end of query: 'into doc('c:\users\lorenzo enzino vinci\desktop\economato\databases\2014.xml')//economato'
so query wrong not know where. can me?
it fails, because invalid xquery update syntax. there not replace ... ... ...
command, there replace ... ...
, error message indicates. unlogical, because $update
holds reference correct xml fragment.
so have use following xquery:
let $update := doc('c:\users\lorenzo enzino vinci\desktop\economato\databases\2014.xml')//economato/protocollo[numero = 1] return replace value of node $update/valido 'false'
also, please note updates not automatically written files in file system (to avoid accidentally overwriting files), e.g. starting basex -u
. explained in detail in basex wiki
Comments
Post a Comment