I'd like to get a list of attributes by a certain name, from a large number of XML-files in a certain folder.
With guidance from this question: XPath Function to query across 50 XML Files?), I'm trying to use XQuery for my file query as well, and installing the .Net version of Saxon I wrote a query like this:
Query.exe -qs:"collection('file:///Temp?select=*.xml')//group[1]/product[1]"
But from that I get everything below the element, including all child nodes. And I can't find a way to get just the attributes (or more specifically a certain "prd_id" attribute).
The XML looks like this (simplified version):
` <group>
<product prd_id="2047">
<articles>art</articles>
<articles>art</articles>
<articles>art</articles>
</product>
</group>
I'd like the result from my XQuery search to be a list of prd_id attributes, or a list of pure product nodes with no child elements (the articles nodes are quite extensive in the real files, and would prevent me from picking out / copying the product attribute in question).
Just adding /@prd_id to the query results in an error like this:
First the query:
>Query.exe -qs:"collection('file:///Temp?select=*.xml')//group[1]/product[1]/@prd_id"
Error on line 1 of module with no systemId:XPTY0004: Cannot create an attribute node (prd_id) whose parent is a document node Query processing failed: Run-time errors were reported
Thanks, Andreas
collection('file:///Temp?select=*.xml')//group[1]/product[1]/@prd_id/string()
might already be enough. – dirkk