Re: Advice On Testing With XML
"Peter A. Bigot" <[email protected]> Thu, 09 Jul 2009 17:46:50 -0500
| Newsgroups | gmane.comp.python.xml |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============1464524216==
Content-Type: multipart/alternative;
boundary="------------020409050707000701070607"
This is a multi-part message in MIME format.
--------------020409050707000701070607
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
I don't grasp exactly what you're trying to do, but if you need a
program that generates XML documents that conform to a schema for which
date values are relative to today, I agree having the harness write the
older date seems to make sense.
If generateDS doesn't fully support all the XML Schema date types, you
could do that using PyXB with a program like this:
import schema
import pyxb.binding.datatypes as xsd
import datetime
delta = xsd.duration('P3D')
s = schema.instance()
s.setElt(datetime.date.today() - delta)
print s.toxml()
with output:
<?xml version="1.0" ?><instance><elt>2009-07-06</elt></instance>
assuming the schema is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="instance" type="structure"/>
<xs:complexType name="structure">
<xs:sequence>
<xs:element name="elt" minOccurs="0" type="xs:date"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
PyXB (see http://pyxb.sourceforge.net) is definitely beta software, but
it's coming along nicely. It makes a strong effort to validate the data
written into the binding instances (in fact, a weakness is that you
can't stop it from trying to validate). It can also handle very complex
schemas, such as those from OpenGIS.
If you really need to change the type of an element in a complex type at
runtime, it could be done by generating a customized binding (though
you'd have to modify the runtime support class
pyxb.binding.basis.element to allow this particular kind of customization).
Peter
Tennis Smith wrote:
> Hi,
>
> I'm looking for some guidence in handling a testing issue. I'm new to
> XML/XSLT, so please bear with me.
>
> First, a little background. My charter is to generate XML test
> messages to make sure we process them correctly. These messages are
> validated against a schema. I'm using generateDS to generate the test
> messages. This ensures the xml is correct.
>
> Everything works great except for one problem that keeps cropping up.
> Some elements cannot be defined easily ahead of time when generating
> the final test document.
>
> For example, a field of type "xs:date" will have to be modifed because
> tests are based on a relative date, not an absolute one. That is,
> dates in tests are based on things like "3 days before today".
>
> Therefore, I'd like to figure out some way to change certain fields
> like date so that I can pass a string and _still validate_ it against
> the schema. Using the example, "-3" would be passed in the date field
> so that the test harness will recognize it as "today - 3 days".
>
> Put another way, the goal is to make this:
> / <xs:element maxOccurs="1" minOccurs="0" name="date" type="xs:date"/>/
> ...behave like this:
> /<xs:element maxOccurs="1" minOccurs="0" name="date" type="xs:string"/>/
>
> Naturally, I can edit and copy/paste into a completely new schema
> file. But I was hoping someone could tell me if I can do some kind of
> XSLT or whatever to get the same effect.
>
> Thanks,
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> XML-SIG maillist - [email protected]
> http://mail.python.org/mailman/listinfo/xml-sig
>
--------------020409050707000701070607
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
I don't grasp exactly what you're trying to do, but if you need a
program that generates XML documents that conform to a schema for which
date values are relative to today, I agree having the harness write the
older date seems to make sense.<br>
<br>
If generateDS doesn't fully support all the XML Schema date types, you
could do that using PyXB with a program like this:<br>
<br>
<tt> import schema<br>
import pyxb.binding.datatypes as xsd<br>
import datetime<br>
<br>
delta = xsd.duration('P3D')<br>
<br>
s = schema.instance()<br>
s.setElt(datetime.date.today() - delta)<br>
print s.toxml()</tt><br>
<br>
with output:<br>
<br>
<tt><?xml version="1.0"
?><instance><elt>2009-07-06</elt></instance><br>
</tt><br>
assuming the schema is:<br>
<br>
<tt><?xml version="1.0" encoding="UTF-8"?><br>
<xs:schema xmlns:xs=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>><br>
<xs:element name="instance" type="structure"/><br>
<xs:complexType name="structure"><br>
<xs:sequence><br>
<xs:element name="elt" minOccurs="0" type="xs:date"/><br>
</xs:sequence><br>
</xs:complexType><br>
</xs:schema></tt><br>
<br>
PyXB (see <a class="moz-txt-link-freetext" href="http://pyxb.sourceforge.net">http://pyxb.sourceforge.net</a>) is definitely beta software, but
it's coming along nicely. It makes a strong effort to validate the
data written into the binding instances (in fact, a weakness is that
you can't stop it from trying to validate). It can also handle very
complex schemas, such as those from OpenGIS.<br>
<br>
If you really need to change the type of an element in a complex type
at runtime, it could be done by generating a customized binding (though
you'd have to modify the runtime support class
pyxb.binding.basis.element to allow this particular kind of
customization).<br>
<br>
Peter<br>
<br>
Tennis Smith wrote:
<blockquote
cite="mid:[email protected]"
type="cite">Hi,<br>
<br>
I'm looking for some guidence in handling a testing issue. I'm new to
XML/XSLT, so please bear with me.<br>
<br>
First,
a little background. My charter is to generate XML test messages to
make sure we process them correctly. These messages are validated
against a schema. I'm using generateDS to generate the test messages.
This ensures the xml is correct.<br>
<br>
Everything works great except for one problem that keeps cropping
up. Some elements cannot be defined easily ahead of time when
generating the final test document. <br>
<br>
For example, a field of
type "xs:date" will have to be modifed because tests are based on a
relative date, not an absolute one. That is, dates in tests are based
on things like "3 days before today". <br>
<br>
Therefore, I'd like to figure out some way to change certain fields
like date so that I can pass a string and _still validate_ it against
the schema. Using the example, "-3" would be passed in the date field
so that the test harness will recognize it as "today - 3 days". <br>
<br>
Put another way, the goal is to make this:<br>
<i> <xs:element maxOccurs="1" minOccurs="0" name="date"
type="xs:date"/></i><br>
...<span style="color: rgb(51, 51, 255);">behave</span> like this:<br>
<i><xs:element maxOccurs="1" minOccurs="0" name="date" type="<span
style="color: rgb(204, 0, 0);">xs:string</span>"/></i><br>
<br>
Naturally, I can edit and copy/paste into a completely new schema
file. But I was hoping someone could tell me if I can do some kind of
XSLT or whatever to get the same effect.<br>
<br>
Thanks,<br>
<font color="#888888"><br>
</font>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
XML-SIG maillist - <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://mail.python.org/mailman/listinfo/xml-sig">http://mail.python.org/mailman/listinfo/xml-sig</a>
</pre>
</blockquote>
<br>
</body>
</html>
--------------020409050707000701070607--
--===============1464524216==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
XML-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
--===============1464524216==--