Hello folks,
I'm using the HTTP Module[1] for sending request. The response has he http:response element which is XML. Then at the end of that element is the body of the response. If your ask for text/plain then you will have the text just after the closing </http:response>.
<http:response status="200" message="OK"> ... </http:response>Hello World!
In my case the media-type of the response is XML. I have something like the following:
<http:response status="200" message="OK"> ... </http:response><service> <hello/> </service>
How am I suppose to parse this output? That is the EXPpath spec, I have to deal with that. But parsing it with BaseX give the following error:
No elements allowed after closed root element.
True, that is not valid XML document. What is the best solution to parse separately the http:response and the body?
Thanks, -- Philippe
I'm using the HTTP Module[1] for sending request. The response has he http:response element which is XML. Then at the end of that element is the body of the response.
http:send-request() will return two items. You can access the second one (the actual result) with a positional predicate:
http:send-request(...)[2]
Christian,
thanks. In fact this path expression work in the context of XQuery code.
http:send-request(...)[2]
But using the CLI with an xml with two elements give me an error
$ echo "<a></a><b></b>" | java -cp basex.jar org.basex.BaseX -i - -q".[2]" "1339078766196.xml" (Line 1): No elements allowed after closed root element.
I have the error even when I use the -i option with an xml file having two elements. My intention was to save the http:send-request output to a file and process it later with a CLI.
Is it the intented behavior of the CLI?
On Wed, Jun 6, 2012 at 6:20 AM, Christian Grün christian.gruen@gmail.com wrote:
I'm using the HTTP Module[1] for sending request. The response has he http:response element which is XML. Then at the end of that element is the body of the response.
http:send-request() will return two items. You can access the second one (the actual result) with a positional predicate:
http:send-request(...)[2]
Okay, I thought that this error came from XQuery. I did not notice before that XQuery can operate on invalid XML document.
Thanks. In fact I can save the response and the body in two different files.
On Thu, Jun 7, 2012 at 10:50 AM, Christian Grün christian.gruen@gmail.com wrote:
But using the CLI with an xml with two elements give me an error
$ echo "<a></a><b></b>" | java -cp basex.jar org.basex.BaseX -i - -q".[2]" "1339078766196.xml" (Line 1): No elements allowed after closed root element.
This is acatually not the fault of the CLI; the -i flag expects a valid XML document as input, and "<a></a><b></b>" does not meet these requirements. It would probably be difficult to extend -i to accept any kind of input, because there are numerous cases in which XQuery results are ambiguous.
What about storing only the actual result of http:send-request in your file? Christian
On Thu, Jun 7, 2012 at 10:26 AM, Philippe Rathé prathe@gmail.com wrote:
Christian,
thanks. In fact this path expression work in the context of XQuery code.
http:send-request(...)[2]
But using the CLI with an xml with two elements give me an error
$ echo "<a></a><b></b>" | java -cp basex.jar org.basex.BaseX -i - -q".[2]" "1339078766196.xml" (Line 1): No elements allowed after closed root element.
I have the error even when I use the -i option with an xml file having two elements. My intention was to save the http:send-request output to a file and process it later with a CLI.
Is it the intented behavior of the CLI?
On Wed, Jun 6, 2012 at 6:20 AM, Christian Grün christian.gruen@gmail.com wrote:
I'm using the HTTP Module[1] for sending request. The response has he http:response element which is XML. Then at the end of that element is the body of the response.
http:send-request() will return two items. You can access the second one (the actual result) with a positional predicate:
http:send-request(...)[2]
Okay, I thought that this error came from XQuery. I did not notice before that XQuery can operate on invalid XML document.
A minor note: XQuery definitely requires well-formed XML as input, but the http:send-request() function generates two results: the first one represents the XML response element, the second one represents the actual result – which is the reason why you need to explicitly choose the second item via "[2]".
On Thu, Jun 7, 2012 at 11:11 AM, Christian Grün christian.gruen@gmail.com wrote:
Okay, I thought that this error came from XQuery. I did not notice before that XQuery can operate on invalid XML document.
A minor note: XQuery definitely requires well-formed XML as input, but the http:send-request() function generates two results: the first one represents the XML response element, the second one represents the actual result – which is the reason why you need to explicitly choose the second item via "[2]".
Does well-formed XML can be invalid XML?
I am confused. If XQuery requires well-formed (or valid) XML, how can it deals with the invalid XML result of http:send-request?
Does well-formed XML can be invalid XML?
The Wikipedia gives you some more information on "well-formed" and "valid" XML documents [1]. Documents are "valid" if they are successfully matched against a schema (usually DTD, XML Schema or RelaxNG).
I am confused. If XQuery requires well-formed (or valid) XML, how can it deals with the invalid XML result of http:send-request?
http:send-request() returns a sequence of two results, each of which is completely well-formed (provided that your result is XML). What you see on your screen is just a textual "serialized" representation of all results; there is no unique bidirectional mapping (Text ↔ XML) for that.
If you want to know more about XQuery and XML, and get more familiar with the wording, you are invited to check out one the available online tutorials, such as [2].
Christian
[1] http://en.wikipedia.org/wiki/XML [2] http://www.w3schools.com/xquery/default.asp
Christian,
thanks for taking your time for some conversations not related to BaseX. I'm hoping to be able to help too in the future.
On Thu, Jun 7, 2012 at 11:57 AM, Christian Grün christian.gruen@gmail.com wrote:
Does well-formed XML can be invalid XML?
The Wikipedia gives you some more information on "well-formed" and "valid" XML documents [1]. Documents are "valid" if they are successfully matched against a schema (usually DTD, XML Schema or RelaxNG).
I am confused. If XQuery requires well-formed (or valid) XML, how can it deals with the invalid XML result of http:send-request?
http:send-request() returns a sequence of two results, each of which is completely well-formed (provided that your result is XML). What you see on your screen is just a textual "serialized" representation of all results; there is no unique bidirectional mapping (Text ↔ XML) for that.
If you want to know more about XQuery and XML, and get more familiar with the wording, you are invited to check out one the available online tutorials, such as [2].
Christian
[1] http://en.wikipedia.org/wiki/XML [2] http://www.w3schools.com/xquery/default.asp
basex-talk@mailman.uni-konstanz.de