I find a useful pattern for this is to write the query so it returns nothing if the input is valid, and returns a document detailing the errors if the input is invalid.

So the query might be:

for $x in doc("stores.xml")/stores/store
 where not($x/state and $x/store-number)
 return <error store="{$x/@id}" desc="store must have both a state and a store-number"/>

The advantage of this approach is that you can report an arbitrary number of errors in a single query.

Michael Kay

On 29/08/2012 12:45, Gleb Gawriljuk wrote:

I hope it is ok to ask generla xQuery questions here.
My Problem: I need to check XML file, whether they have a certain structure with certain node-names. However I can only use xQuery  but no schema(e.g. XSD) with Saxon 8.9(cannot use different version) 
I tryied folowing xquery to validate a store node: 

 for $x in doc("stores.xml")/stores/store
 where $x/state and $x/store-number
 return $x

How ever, no error is returned if the where-conditions are not fullfiled. I just get an empty xml.
So is there a way to validated a xml so that, if the structure( or even the node names) are not valid saxon would return an error?

Kind regards,

Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

saxon-help mailing list archived at http://saxon.markmail.org/