XQuery - search files collection and return attribute or element without children



I'd like to get a list of attributes by a certain name, from a large number of XML-files in a certain folder.


I'm trying to use XQuery for this, 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


No comments:

Post a Comment