如何将使用WebServices返回的XML解析为xQuery?
我已经为这个问题苦苦挣扎了几天,衷心感谢您的帮助。我有一个 Java 应用程序,它查询多个返回 XML 消息的 Web 服务。然后,我的应用程序解析使用 xquery 返回的多个 XML 消息。根据我的理解,xquery 需要一个 XML 文档来读取 XML,对于我的 Java 应用程序来说,为返回的每个 Web 服务 XML 创建一个 XML 文档会很繁重,并且会减慢响应时间。
有没有什么方法可以将 Webservices 调用返回的 XML 字符串直接作为 xquery 的输入传递,而无需创建 XML 文档?来自单个源的 XML 是一致的,但 XML 结构在多个 Web 服务调用中是不同的,因此我需要一个非常灵活的应用程序处理框架。
先感谢您。 尼尔.
I have been struggling with this issue for a few days now and would sincerely appreciate your help . I have an Java application that queries multiple Webservices which return an XML message. My application then parses these multiple XML messages returned using xquery. Based on what i understand, xquery needs a XML document to read the XML and for my Java application creating a XML document for each Webservices XML returned would be heavy and slow down the response time.
Is there any way, that the XML string returned by the Webservices call can be passed directly as an input to xquery without creating the XML document? The XML from a single source is consistent but the XML structure is different in the multiple Webservices call so i need a very flexible application processing framework.
Thank you in advance.
Neil.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
String 是字符串,而 XQuery/XPath 需要一个带有命名空间、元素和属性的解析对象。这就是为什么需要解析。
你可以传递一个 InputSource 而不是 DOM,但我被告知它无论如何都会在后台构建一个 DOM。
String is string, while XQuery/XPath requires a parsed object with namespaces, elements and attributes. That's why parsing is required.
You may pass an InputSource instead of DOM, but I was told it builds a DOM under the hood anyway though.
不,XQuery 对 XML 文档进行操作。您可以将字符串传递给 XQuery 应用程序,它会被视为字符串,而不是 XML 文档。
例如:
可以使用任何接受字符串参数的函数进行处理,例如:
string-length()
、substring()
、matches()
、tokenize()
、replace()
、...等但是,尝试将此字符串视为 XML 文档 - 例如尝试计算 XPath 表达式,例如:
在此字符串上不可能,当然除非它被解析。
No, XQuery operates on XML document(s). You can pass a string to an XQuery application, and it is treated as string, not as XML document.
For example:
can be processed with any function that accepts string argument(s), such as:
string-length()
,substring()
,matches()
,tokenize()
,replace()
, ..., etc.However, trying to treat this string as XML document -- for example trying to evaluate an XPath expression like:
is not possible on this string, unless of course it is parsed.