Amrit
Amrit

Reputation: 2333

XQuery: Compare xml node value with a value stored in disk file

I am looking for a method via which we can compare an xml node value with a node value stored in a disk file. In short, how to read the xml file in xquery?

I am using SoapUI for testing a RESTful service where I want to check the contents of a response with the contents of a file stored on disk.

Is such thing possible in xquery?

I have tried the following example:

//customer/id=doc("C:\\Documents and Settings\\Testing related\\cust.xml")/customer/id

Upvotes: 1

Views: 441

Answers (2)

Jens Erat
Jens Erat

Reputation: 38712

Use deep-equal($node1, $node2) for comparing whole subtrees.

deep-equal(//customer/id, doc("cust.xml")/customer/id)

If there are multiple customer ids, you will have to loop over them yourself; deep-equal does not have the same "set semantics" like = has.

Opening documents with doc(...) is somewhat implementation dependent. SOAPUI uses Saxon to evaluate XPath and XQuery, so read their documentation on the doc(...) function to realize they want the URI of the element, like you could pass one to Java's URIResolver class.

doc("file:///C:/Documents and Settings/Testing related/cust.xml")

Upvotes: 3

Ewout Graswinckel
Ewout Graswinckel

Reputation: 1273

I think you should use a file uri: http://en.wikipedia.org/wiki/File_URI_scheme but I'm not 100% sure if this is something implementation dependent. At least the following works in xDB:

doc("file:///c:/path/to/file.xml")

Upvotes: 1

Related Questions