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
?
我正在寻找一种方法,通过这种方法,我们可以将xml节点值与存储在磁盘文件中的节点值进行比较。简而言之,如何在xquery中读取xml文件?
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.
我正在使用SoapUI来测试一个RESTful服务,在这个服务中,我希望用存储在磁盘上的文件的内容来检查响应的内容。
Is such thing possible in xquery
?
在xquery中,这是可能的吗?
I have tried the following example:
我尝试过以下例子:
//customer/id=doc("C:\\Documents and Settings\\Testing related\\cust.xml")/customer/id
2 个解决方案
#1
3
Use deep-equal($node1, $node2)
for comparing whole subtrees.
使用深度相等($node1, $node2)来比较整个子树。
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.
如果有多个客户id,您必须自己对它们进行循环;deep-equal没有与=相同的“set语义”。
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(…)打开文档有点依赖于实现。SOAPUI使用Saxon来评估XPath和XQuery,所以请阅读它们关于doc(…)函数的文档,以了解它们需要元素的URI,就像您可以将一个URI传递给Java的URIResolver类一样。
doc("file:///C:/Documents and Settings/Testing related/cust.xml")
#2
1
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:
我认为您应该使用一个文件uri: http://en.wikipedia.org/wiki/File_URI_scheme,但我不能100%确定这是否与实现相关。在xDB中至少有以下工作:
doc("file:///c:/path/to/file.xml")
#1
3
Use deep-equal($node1, $node2)
for comparing whole subtrees.
使用深度相等($node1, $node2)来比较整个子树。
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.
如果有多个客户id,您必须自己对它们进行循环;deep-equal没有与=相同的“set语义”。
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(…)打开文档有点依赖于实现。SOAPUI使用Saxon来评估XPath和XQuery,所以请阅读它们关于doc(…)函数的文档,以了解它们需要元素的URI,就像您可以将一个URI传递给Java的URIResolver类一样。
doc("file:///C:/Documents and Settings/Testing related/cust.xml")
#2
1
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:
我认为您应该使用一个文件uri: http://en.wikipedia.org/wiki/File_URI_scheme,但我不能100%确定这是否与实现相关。在xDB中至少有以下工作:
doc("file:///c:/path/to/file.xml")