0

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.

2 Answers2

1

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.

Jens Erat
  • 37,523
  • 16
  • 80
  • 96
0

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.

wcandillon
  • 2,086
  • 19
  • 19
  • wcandillon-thanks I have upodated my question. I am using XML Database BaseX. –  Aug 02 '12 at 07:53