How to parse XML returned using WebServices to xQuery?
I have been struggling wit开发者_如何学Ch 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.
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.
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?
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:
"<t name='Ann'/>"
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:
/t/@name
is not possible on this string, unless of course it is parsed.
精彩评论