문제

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
도움이 되었습니까?

해결책

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")

다른 팁

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")
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top