Re: testing xml/xslt with perl?

Maurice Mengel <[email protected]> Sun, 23 Jan 2011 11:10:42 -0500
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Thanks for your quick responses! I have heard before that schematron
and RelaxNG can test content much more than XSD usually does, but
never really looked at them. I will have another look.

I have xsd schems for both input and output formats, but they say next
to nothing about the content.
So I  am thinking about writing simple tests like these (likely in
perl to save time, but for illustration also in xml)

my %transforms = (
	'a name' => {
		in    => '01.mpx',
		out   => '01.dc_oai',
		tests => {
			input  => [ '//xpath', 'Jane Eyre' ],
			output => [ '//xpath', 'Jane Eyre' ],
		}
	},
);

__DATA__
<simplexmltests>
 <!-- a transform test is one which tests input and output -->
 <transform name="title" in="01.mpx" out="01.oai_dc">
  <input xpath="//titel">Jane Eyre</input>
  <output xpath="//title">Jane Eyre</output>
 </transform>

 <!-- an output test tests only if output value in output document-->
 <output name="title" document="01.dc_oai" xpath="//title">Robinson
Crusoe<output>
</simplexmltest>

It should be fairly easy to write a script that
a) creates the output document from input and xslt
b) validates my input and output documents against xsd
c) tests each of these rules specified above
d) reports on each test to STDOUT/STDERR similar to Test::More (ok or fail)

The question is if it is worth the trouble or if any available
technology does this already. What do you think?

Using RelaxNG or schematron I would have to recreate the general
schema definition first before I can specify content. I think this is
error prone and or least a lengthly process. Also those formats
describe all
possible documents. In contrast to that, I would just work with a few
example documents (pairs of input and output)
hoping that works for future (more complicated) cases as well. I think
that resembles the philosophy of tests like those of Test::More.

thanks
maurice


On Sun, Jan 23, 2011 at 10:41 AM, Vaclav Barta <[email protected]> wrote:
> On Sunday 23 January 2011 16:20:20 Michael Ludwig wrote:
>> Maurice Mengel schrieb am 23.01.2011 um 09:49 (-0500):
>> > Soon, I will have to write some xslt which transfers xml to xml. I did
>> > this before and testing for well-formedness and validity (xsd) didn't
>> > prevent me from building in subtle errors over time. So, I wonder if I
>> > should write tests this time, particularly if I should use Test::More.
>> If you're into Perl programming, you should definitely get acquainted
>> with Test::More. Real-life Perl frequently is, unfortunately, a
> I'm testing XML transformations in Perl (not XSLT, but XS on top of libxml2)
> with Test::More, comparing the transformation's result with a precomputed
> value, and it's a pain - different versions of libxml2 keep changing the
> generated text (mostly whitespace, but also namespace declarations and other
> "non-semantic" changes), breaking my tests. I must admit the pain hadn't been
> sharp enough to drive me to an alternative yet, :-) but if you know any, I
> certainly would like to hear about it...
>
>        Bye
>                Vasek
> --
> http://www.mangrove.cz/
> Open Source integration
> _______________________________________________
> Perl-XML mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs