[
Lists Home |
Date Index |
Thread Index
]
Dave Pawson wrote:
>On Thu, 2005-06-23 at 13:40 +0200, James Fuller wrote:
>
>
>
>>sun msv will generate random or not random instances of data based on a
>>variety of supplied schemas...though be warned its a bit fiddly.
>>
>>
>
>As in...
> I couldn't get it to work at all Jim?
>
>rng Schema, it kept giving me an exception.
>
>
sorry wasnt super clear in last post
I use it in the context of Sun's XML instance generator (which uses
MSV)...once u get it working its great for creating huge numbers of test
cases (lets say xslt)
get it from here
http://www.sun.com/software/xml/developers/instancegenerator/
here is an ant snippet for running it
<java fork="true" jar="../lib/xmlgen4/xmlgen.jar" failonerror="no">
<!-- if not set you wont see important error messages! -->
<arg value="-warning"/>
<!-- set number of instances you want generated -->
<arg value="-n"/>
<arg value="100"/>
<!-- set namespaced root element, this is crucial! -->
<arg value="-root"/>
<arg value="{http://www.w3.org/1999/XSL/Transform}stylesheet"/>
<!-- i use dtd -->
<arg value="-dtd"/>
<arg value="../etc/simple-xslt.dtd"/>
<!-- provide filename template, where dollar sign gets replaced with
instance number -->
<arg value="instance/test.$.xslt"/>
<!-- explicitly tell Ant dependencies -->
<classpath>
<pathelement location="../lib/xmlgen4/xsdlib.jar"/>
<pathelement location="../lib/xmlgen4/isorelax.jar"/>
<pathelement location="../lib/xmlgen4/msv.jar"/>
<pathelement location="../lib/xmlgen4/relaxngDatatype.jar"/>
<pathelement location="../lib/xmlgen4/xercesImpl.jar"/>
<pathelement location="../lib/xmlgen4/xml-apis.jar"/>
<pathelement location="../lib/xmlgen4/xmlgen.jar"/>
</classpath>
</java>
note the -root switch needs to have namespace or nothing works...in fact
I couldnt get anything working without a namespace..there is some real
weirdness going on with this....but got it working in the end with these
settings.
I use a simple dtd (though this works with RelaxNG and XML Schema)
which is a 'cut down' version of the complete XSLT language
hth, Jim Fuller
have included dtd below.
simple-xslt.dtd
------------------------------------------------------------------------------------------------------------
<!ENTITY % result-elements " ns2:a | ns2:b | ns2:c | ns2:d">
<!ENTITY % char-instructions "
xsl:for-each
| xsl:value-of
| xsl:copy-of
| xsl:choose
| xsl:if
| xsl:copy
| xsl:variable
">
<!ENTITY % char-instructions-for-param "
xsl:for-each
| xsl:value-of
| xsl:copy-of
| xsl:choose
| xsl:if
| xsl:copy
">
<!ENTITY % instructions "
%char-instructions;
| xsl:element
">
<!ENTITY % char-template "
%char-instructions;
">
<!ENTITY % template "
%instructions; |
%result-elements;
">
<!ENTITY % top-level "
xsl:variable?
| xsl:param?
| xsl:template+
">
<!-- Used for the type of an attribute value that is a URI reference.-->
<!ENTITY % URI "CDATA">
<!-- Used for the type of an attribute value that is a pattern.-->
<!ENTITY % pattern "CDATA">
<!-- Used for the type of an attribute value that is an
attribute value template.-->
<!ENTITY % avt "(ns2:a1 ns2:a2 ns2:a3 ns2:a4 ns2:a5)">
<!-- Used for the type of an attribute value that is a QName; the prefix
gets expanded by the XSLT processor. -->
<!ENTITY % qname "(q1 q2 q3 q4 q5 q6 q7 q8 q9)">
<!-- Like qname but a whitespace-separated list of QNames. -->
<!ENTITY % qnames "(qn1 qn2 qn3 qn4 qn5 qn6 qn7 qn8 qn9)">
<!-- Used for the type of an attribute value that is an expression.-->
<!ENTITY % expr "( %result-elements; | --SLASH-- )">
<!ENTITY % testexpr "( %result-elements; )">
<!-- Used for the type of an attribute value that consists
of a single character.-->
<!ENTITY % char "CDATA">
<!-- ........................................................... -->
<!ELEMENT ns2:a (%template;)*>
<!ELEMENT ns2:b (%template;)*>
<!ELEMENT ns2:c (%template;)*>
<!ELEMENT ns2:d (%template;)*>
<!-- ........................................................... -->
<!ELEMENT xsl:stylesheet (%top-level;)*>
<!ATTLIST xsl:stylesheet
xsl:version (2.0) #REQUIRED
xmlns:xsl CDATA #FIXED "http://www.w3.org/1999/XSL/Transform"
xmlns:ns2 CDATA #FIXED "http://www.ruminate.co.uk/test"
>
<!ELEMENT xsl:template ( %instructions; | %result-elements; | xsl:param)* >
<!ATTLIST xsl:template
xsl:match %expr; #REQUIRED
>
<!ELEMENT xsl:value-of EMPTY>
<!ATTLIST xsl:value-of
xsl:select %expr; #REQUIRED
>
<!ELEMENT xsl:copy-of EMPTY>
<!ATTLIST xsl:copy-of
xsl:select %expr; #REQUIRED>
<!ELEMENT xsl:apply-templates (xsl:sort|xsl:with-param)*>
<!ATTLIST xsl:apply-templates
xsl:select %expr; #REQUIRED
>
<!ELEMENT xsl:if EMPTY>
<!ATTLIST xsl:if
xsl:test %testexpr; #REQUIRED >
<!ELEMENT xsl:for-each
(%result-elements;
| xsl:sort)*
>
<!ATTLIST xsl:for-each
xsl:select %expr; #REQUIRED
>
<!ELEMENT xsl:sort EMPTY>
<!ATTLIST xsl:sort
xsl:select %expr; "."
>
<!ELEMENT xsl:choose (xsl:when+, xsl:otherwise?)>
<!ELEMENT xsl:when (%template;)*>
<!ATTLIST xsl:when
xsl:test %testexpr; #REQUIRED
>
<!ELEMENT xsl:otherwise (%template;)*>
<!ELEMENT xsl:variable (%template;)*>
<!ATTLIST xsl:variable
xsl:name %qname; #REQUIRED
>
<!ELEMENT xsl:param (%char-instructions-for-param;)*>
<!ATTLIST xsl:param
xsl:name %qname; #REQUIRED
>
<!ELEMENT xsl:element (xsl:attribute+ | %template;)*>
<!ATTLIST xsl:element
xsl:name %avt; #REQUIRED
>
<!ELEMENT xsl:attribute (%char-template;)*>
<!ATTLIST xsl:attribute
xsl:name %avt; #REQUIRED
>
<!ELEMENT xsl:copy (%template;)*>
<!ELEMENT xsl:with-param (%template;)*>
<!ATTLIST xsl:with-param
xsl:name %qname; #REQUIRED
xsl:select %expr; #REQUIRED
>
|