Domanda

I have 2 XML files -

File1.xml

<Fruits>
   <F>Apple</F>
   <F>Pineapple</F>
   <F>Orange</F>
   <F>Banana</F>
</Fruits>

File2.xml

<Fruits>
   <F>Grapes</F>
   <F>Peach</F>
   <F>Watermelon</F>
   <F>Chickoo</F>
</Fruits>

I want to update/insert the File1.xml with the data from File2.xml so that I have File1.xml as -

File1.xml

<Fruits>
   <F>Apple</F>
   <F>Pineapple</F>
   <F>Orange</F>
   <F>Banana</F>
   <F>Grapes</F>
   <F>Peach</F>
   <F>Watermelon</F>
   <F>Chickoo</F>
</Fruits>

How to do this using XQuery/XQuery Update? I am using XML Database BaseX.

È stato utile?

Soluzione

If you are using XQuery without a database context, Zorba has a file module if you want to update the content of a file. You can check it out at http://www.zorba-xquery.com/html/modules/expath/file.

If you are using an XML database, you can write the following update expression: insert nodes $file2/Fruits/F into $file1/Fruits $file1 and $file2 are depending on the kind of database you're using.

Altri suggerimenti

This can easily be done using XQuery Update:

insert nodes doc("File2")/Fruits/F as last into doc("File1")/Fruits

You can also change the database name to file names if you only stored the files on your hard disk, not as a database.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top