Serializing unescaped xml to string
Hi all, Is there a way to output unescaped XML to a string for debugging purposes? In unittests we would like to output the XML returned when a test fails, here is my example: declare %unit:test function elementinfo-test:test-element-info() { let $cases := <cases> <case> <comment>Failed input</comment> <input>input</input> <output> <result> output </result> </output> </case> </cases> for $case in $cases/case let $result := {some function which returns XML} let $u := unit:assert(deep-equal($case/output, result), $case/comment/text() || " Input: " || $case/input/text() || " Expected: " || fn:serialize($case/output) || " Got: " || fn:serialize($result)) return $u }; But when a test fails, I get escaped XML as the output. Is there any way to get this as actual XML? Thanks, Joe
On Wed, 2013-12-04 at 19:59 -0800, Joe Templeman wrote:
Hi all,
Is there a way to output unescaped XML to a string for debugging purposes? In unittests we would like to output the XML returned when a test fails, here is my example: [...] || " Got: " || fn:serialize($result)) return $u };
But when a test fails, I get escaped XML as the output. Is there any way to get this as actual XML?
( "Input: ", $case/input/text(), " Expected: " , $case/output, "Got:", $result) || " Got: " || as a sequence... Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org freenode/#xml
Hi Joe, one solution is to use "text" as serialization method: serialize("<a/>", { 'method': 'text'}) As an alternative, you can specify in the query prolog (the beginning) of your query that all results are to be output as text: declare option output:method "text"; Hope this helps, Christian ___________________________ On Thu, Dec 5, 2013 at 4:59 AM, Joe Templeman <joe@inkling.com> wrote:
Hi all,
Is there a way to output unescaped XML to a string for debugging purposes? In unittests we would like to output the XML returned when a test fails, here is my example:
declare %unit:test function elementinfo-test:test-element-info() { let $cases := <cases> <case> <comment>Failed input</comment> <input>input</input> <output> <result> output </result> </output> </case> </cases> for $case in $cases/case let $result := {some function which returns XML} let $u := unit:assert(deep-equal($case/output, result), $case/comment/text() || " Input: " || $case/input/text() || " Expected: " || fn:serialize($case/output) || " Got: " || fn:serialize($result)) return $u };
But when a test fails, I get escaped XML as the output. Is there any way to get this as actual XML?
Thanks, Joe
_______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
When I do { 'method': 'text'} I just get the text from the XML, not the XML itself: <testcase name="test-element-info" time="PT0.011S"> <failure message="Failed input Input: input Expected: output Got: {removed}" type="UNIT0001"/> </testcase> What I would like is ".. Expected: <result>output</result> ..." since what is being returned is XML. On Thu, Dec 5, 2013 at 3:02 AM, Christian Grün <christian.gruen@gmail.com>wrote:
Hi Joe,
one solution is to use "text" as serialization method:
serialize("<a/>", { 'method': 'text'})
As an alternative, you can specify in the query prolog (the beginning) of your query that all results are to be output as text:
declare option output:method "text";
Hope this helps, Christian ___________________________
On Thu, Dec 5, 2013 at 4:59 AM, Joe Templeman <joe@inkling.com> wrote:
Hi all,
Is there a way to output unescaped XML to a string for debugging purposes? In unittests we would like to output the XML returned when a test fails, here is my example:
declare %unit:test function elementinfo-test:test-element-info() { let $cases := <cases> <case> <comment>Failed input</comment> <input>input</input> <output> <result> output </result> </output> </case> </cases> for $case in $cases/case let $result := {some function which returns XML} let $u := unit:assert(deep-equal($case/output, result), $case/comment/text() || " Input: " || $case/input/text() || " Expected: " || fn:serialize($case/output) || " Got: " || fn:serialize($result)) return $u };
But when a test fails, I get escaped XML as the output. Is there any way to get this as actual XML?
Thanks, Joe
_______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Hi Joe,
<testcase name="test-element-info" time="PT0.011S"> <failure message="Failed input Input: input Expected: output Got: {removed}" type="UNIT0001"/> </testcase>
What I would like is ".. Expected: <result>output</result> ..." since what is being returned is XML.
This is syntactically not possible, because "<" cannot occur in attribute values. The following XML is not well-formed: <x a="<"/> However, it’s possible to output the value of an attribute as string, and then skip the entity encoding: declare option output:method "text"; let $expected := serialize(<a/>) let $xml := <failure message="Expected: { $expected }"/> return $xml/@message/string() Hope this helps, Christian
Ah that makes sense. Is there no way then to return a message from a unittest which contains XML? The framework creates the <failure> blocks based on the result of assertions so I don't have control over what is displayed it seems. On Thu, Dec 5, 2013 at 12:56 PM, Christian Grün <christian.gruen@gmail.com>wrote:
Hi Joe,
<testcase name="test-element-info" time="PT0.011S"> <failure message="Failed input Input: input Expected: output Got: {removed}" type="UNIT0001"/> </testcase>
What I would like is ".. Expected: <result>output</result> ..." since what is being returned is XML.
This is syntactically not possible, because "<" cannot occur in attribute values. The following XML is not well-formed:
<x a="<"/>
However, it’s possible to output the value of an attribute as string, and then skip the entity encoding:
declare option output:method "text"; let $expected := serialize(<a/>) let $xml := <failure message="Expected: { $expected }"/> return $xml/@message/string()
Hope this helps, Christian
Ah that makes sense. Is there no way then to return a message from a unittest which contains XML? The framework creates the <failure> blocks based on the result of assertions so I don't have control over what is displayed it seems.
We could possibly extend the existing Unit Module with additional functions or function arguments. Could you please give an example on how the testing output, or the Unit function signatures, should ideally look like in your opinion? Thanks, Christian
Hi, I've done something similar (I think) in BaseX using the serialize() function (XPath 3.0). It was easy enough that I suspect I don't understand the requirement here. As Christian points out, XML doesn't allow you to represent XML directly in an attribute value; I used an element. When using the text output method it comes out as XML (because it's already been serialized). When using the XML output method, it comes out escaped (as it should be). Cheers, Wendell Wendell Piez | http://www.wendellpiez.com XML | XSLT | electronic publishing Eat Your Vegetables _____oo_________o_o___ooooo____ooooooo_^ On Thu, Dec 5, 2013 at 4:04 PM, Joe Templeman <joe@inkling.com> wrote:
Ah that makes sense. Is there no way then to return a message from a unittest which contains XML? The framework creates the <failure> blocks based on the result of assertions so I don't have control over what is displayed it seems.
On Thu, Dec 5, 2013 at 12:56 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Joe,
<testcase name="test-element-info" time="PT0.011S"> <failure message="Failed input Input: input Expected: output Got: {removed}" type="UNIT0001"/> </testcase>
What I would like is ".. Expected: <result>output</result> ..." since what is being returned is XML.
This is syntactically not possible, because "<" cannot occur in attribute values. The following XML is not well-formed:
<x a="<"/>
However, it’s possible to output the value of an attribute as string, and then skip the entity encoding:
declare option output:method "text"; let $expected := serialize(<a/>) let $xml := <failure message="Expected: { $expected }"/> return $xml/@message/string()
Hope this helps, Christian
_______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Hi Joe, a little preview: I agree that the current output of the unit reporting functions is not as convenient as it could be. This is why we’ll soon extend the XML testcase output, and add some more functions like unit:assert-equals() which will create a more helpful error output. Best, Christian ___________________________ On Thu, Dec 5, 2013 at 4:59 AM, Joe Templeman <joe@inkling.com> wrote:
Hi all,
Is there a way to output unescaped XML to a string for debugging purposes? In unittests we would like to output the XML returned when a test fails, here is my example:
declare %unit:test function elementinfo-test:test-element-info() { let $cases := <cases> <case> <comment>Failed input</comment> <input>input</input> <output> <result> output </result> </output> </case> </cases> for $case in $cases/case let $result := {some function which returns XML} let $u := unit:assert(deep-equal($case/output, result), $case/comment/text() || " Input: " || $case/input/text() || " Expected: " || fn:serialize($case/output) || " Got: " || fn:serialize($result)) return $u };
But when a test fails, I get escaped XML as the output. Is there any way to get this as actual XML?
Thanks, Joe
_______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Feel free to check out the updated example in our Wiki [1] and the latest snapshot [2]. [1] http://docs.basex.org/wiki/Unit_Module [2] http://files.basex.org/releases/latest/ ___________________________ On Sat, Dec 14, 2013 at 5:35 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Joe,
a little preview: I agree that the current output of the unit reporting functions is not as convenient as it could be. This is why we’ll soon extend the XML testcase output, and add some more functions like unit:assert-equals() which will create a more helpful error output.
Best, Christian ___________________________
On Thu, Dec 5, 2013 at 4:59 AM, Joe Templeman <joe@inkling.com> wrote:
Hi all,
Is there a way to output unescaped XML to a string for debugging purposes? In unittests we would like to output the XML returned when a test fails, here is my example:
declare %unit:test function elementinfo-test:test-element-info() { let $cases := <cases> <case> <comment>Failed input</comment> <input>input</input> <output> <result> output </result> </output> </case> </cases> for $case in $cases/case let $result := {some function which returns XML} let $u := unit:assert(deep-equal($case/output, result), $case/comment/text() || " Input: " || $case/input/text() || " Expected: " || fn:serialize($case/output) || " Got: " || fn:serialize($result)) return $u };
But when a test fails, I get escaped XML as the output. Is there any way to get this as actual XML?
Thanks, Joe
_______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
Nice! Thanks for updating that, it'll be a huge help On Sun, Dec 15, 2013 at 7:37 AM, Christian Grün <christian.gruen@gmail.com>wrote:
Feel free to check out the updated example in our Wiki [1] and the latest snapshot [2].
[1] http://docs.basex.org/wiki/Unit_Module [2] http://files.basex.org/releases/latest/ ___________________________
On Sat, Dec 14, 2013 at 5:35 PM, Christian Grün <christian.gruen@gmail.com> wrote:
Hi Joe,
a little preview: I agree that the current output of the unit reporting functions is not as convenient as it could be. This is why we’ll soon extend the XML testcase output, and add some more functions like unit:assert-equals() which will create a more helpful error output.
Best, Christian ___________________________
On Thu, Dec 5, 2013 at 4:59 AM, Joe Templeman <joe@inkling.com> wrote:
Hi all,
Is there a way to output unescaped XML to a string for debugging purposes? In unittests we would like to output the XML returned when a test fails, here is my example:
declare %unit:test function elementinfo-test:test-element-info() { let $cases := <cases> <case> <comment>Failed input</comment> <input>input</input> <output> <result> output </result> </output> </case> </cases> for $case in $cases/case let $result := {some function which returns XML} let $u := unit:assert(deep-equal($case/output, result), $case/comment/text() || " Input: " || $case/input/text() || " Expected: " || fn:serialize($case/output) || " Got: " || fn:serialize($result)) return $u };
But when a test fails, I get escaped XML as the output. Is there any way to get this as actual XML?
Thanks, Joe
_______________________________________________ BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
participants (4)
-
Christian Grün -
Joe Templeman -
Liam R E Quin -
Wendell Piez