Christian,
Thank you! That was exactly what I was looking for & somehow far simpler than I thought it needed to be.
-Dave
On Mon, Oct 15, 2018 at 9:07 AM Christian Grün christian.gruen@gmail.com wrote:
Hi Dave,
here is one way to do it:
declare context item := db:open('catalog'); declare variable $update := 'daily-update.xml';
for $new in doc($update)//ENTRY let $old := //ENTRY[SKU = $new/SKU] return if($old) then ( replace node $old with $new ) else ( insert node $new into /CATALOG/ENTRIES )
Hope this helps, Christian
On Sun, Oct 14, 2018 at 12:10 AM Dave Kopecek dave.kopecek@gmail.com wrote:
Here are some tweaked examples & better problem definition:
Given a database created from catalog.xml below, what's the best way to
update & add records received daily as in file daily-update.xml?
For every <ENTRY> node in daily-update.xml -- If ENTRY/SKU found in catalog.xml replace the entire <ENTRY> node in
catalog.xml with the one from daily-update.xml
-- If ENTRY/SKU not found in catalog.xml add the <ENTRY> node from
daily-update.xml to catalog.xml
catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG> <ENTRIES> <ENTRY> <SKU>1</SKU> <TITLE>Empire Burlesque</TITLE> <ARTIST>Dylan</ARTIST> <PRICE>10.90</PRICE> </ENTRY> <ENTRY> <SKU>2</SKU> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <PRICE>9.90</PRICE> </ENTRY> </ENTRIES> </CATALOG>
daily-update.xml
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG> <ENTRIES> <ENTRY> <SKU>1</SKU> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <PRICE>29.99</PRICE> <NEWTHING>some value</NEWTHING> </ENTRY> <ENTRY> <SKU>5</SKU> <TITLE>Tupelo Honey</TITLE> <ARTIST>Van Morrison</ARTIST> <PRICE>8.20</PRICE> </ENTRY> </ENTRIES> </CATALOG>
catalog.xml after daily update:
<CATALOG> <ENTRIES> <ENTRY> <SKU>1</SKU> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <PRICE>29.99</PRICE> <NEWTHING>some value</NEWTHING> </ENTRY> <ENTRY> <SKU>2</SKU> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <PRICE>9.90</PRICE> </ENTRY> <ENTRY> <SKU>5</SKU> <TITLE>Tupelo Honey</TITLE> <ARTIST>Van Morrison</ARTIST> <PRICE>8.20</PRICE> </ENTRY> </ENTRIES> </CATALOG>
Thanks, -Dave
On Fri, Aug 17, 2018 at 11:27 AM Dave Kopecek dave.kopecek@gmail.com
wrote:
Hi All,
Given a database created from catalog.xml below. What's the best way to
update & add records received daily as in file daily-update.xml ?
Coming from relational DBs & new to this. I ultimately need to
script/automate this. Hoping there's some magic command I'm missing & looking for best way to approach the problem.
Thanks, -Dave
catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG> <ENTRIES> <ENTRY> <SKU>1</SKU> <TITLE>Empire Burlesque</TITLE> <ARTIST>Dylan</ARTIST> <PRICE>10.90</PRICE> </ENTRY> <ENTRY> <SKU>2</SKU> <TITLE>Hide your heart</TITLE> <ARTIST>Bonnie Tyler</ARTIST> <PRICE>9.90</PRICE> </ENTRY> </ENTRIES> </CATALOG>
daily-update.xml
<?xml version="1.0" encoding="UTF-8"?>
<CATALOG> <ENTRIES> <ENTRY> <SKU>1</SKU> <PRICE>19.90</PRICE> <NEWTHING>I wasn't here before the update</NEWTHING> </ENTRY> <ENTRY> <SKU>1971</SKU> <TITLE>Tupelo Honey</TITLE> <ARTIST>Van Morrison</ARTIST> <PRICE>8.20</PRICE> </ENTRY> </ENTRIES> </CATALOG>
-- DAVE KOPECEK OFFICE 607-431-8565 CELL 607-267-3449 6 CROSS STREET, DELHI NY 13753