[XML-SIG] Advice On Testing With XML
Peter A. Bigot
bigotp at acm.org
Fri Jul 10 00:46:50 CEST 2009
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 pyxb.binding.datatypes as xsd
delta = xsd.duration('P3D')
s = schema.instance()
s.setElt(datetime.date.today() - delta)
<?xml version="1.0" ?><instance><elt>2009-07-06</elt></instance>
assuming the schema is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:element name="instance" type="structure"/>
<xs:element name="elt" minOccurs="0" type="xs:date"/>
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).
Tennis Smith wrote:
> 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.
> XML-SIG maillist - XML-SIG at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the XML-SIG