[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Instance from Schema?

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

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 -->
        <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"/>

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

 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.


 <!ENTITY % result-elements " ns2:a | ns2:b | ns2:c | ns2:d">
 <!ENTITY % char-instructions "
 | xsl:value-of
 | xsl:copy-of
 | xsl:choose
 | xsl:if
 | xsl:copy
 | xsl:variable

  <!ENTITY % char-instructions-for-param "
  | xsl:value-of
  | xsl:copy-of
  | xsl:choose
  | xsl:if
  | xsl:copy
 <!ENTITY % instructions "
 | xsl:element
 <!ENTITY % char-template "
 <!ENTITY % template "
 %instructions; |
 <!ENTITY % top-level "
 | xsl:param?
 | xsl:template+
 <!-- Used for the type of an attribute value that is a URI reference.-->
 <!-- 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
 | 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


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.

Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.