In my most recent attempt to access the XML database from my nightmares, I've come very close. I actually succeeded, using the test database; however, when I apply it to the database I'm actually trying to access, rather than the BaseX sample database, I get a special brand of error, which is a valid complaint about the XML file:
via http://basex.org/products/live-demo/
doc('test') :=
<item>
<item_number>1171270</item_number>
<seller_info>
<seller_company_id>6356</seller_company_id>
<seller_rating>C31</seller_rating>
<seller_rating>T150 hr.</seller_rating>
</seller_info>
<product_info>
<unit>2022</unit>
<sinfo>55 cases</sinfo>
<sinfo>Yu-gi-oh trading card pack</sinfo>
<sinfo>.45kg per unit</sinfo>
<sinfo>24.7500kg shipment</sinfo>
</product_info>
<product_info>
<unit>9291</unit>
<sinfo>7 units</sinfo>
<sinfo>Naruto, Classic, action figure</sinfo>
<sinfo>1.8kg per unit</sinfo>
<sinfo>12.6kg shipment</sinfo>
</product_info>
</item>
0: write your own query... :=
let $doc := doc('test')
for $v in $doc//item
where contains($v/product_info/unit,'9291')
return
$v/seller_info/seller_company_id
Returns:
Error:
Stopped at line 3, column 39: [XPTY0004] Single item expected, (element unit { ... }, element unit { ... }) found.
I can't say I didn't expect to encounter a problem like this. Unfortunately, I didn't format the XML document--someone else did--, and it's all terribly formatted, as you can see. Part of the reason I'm trying to access it: to restructure it.
Is there a way to run the query I'm trying to run on the document and get results without having this error spit at me? I'm also looking at the error of having Single item expected
in my returns, when I try to target sinfo
as a return value, right? Is there any way to get, for example, all of the sinfo's
? Or how about only the second sinfo for each product_info
without having this nasty error spit back at me?