[xsd-users] xsd does not like my xsd schema file

Erik Sjölund erik.sjolund at gmail.com
Tue Jan 19 04:02:47 EST 2010


on 2010-01-19 00:26 Ramon F Herrera wrote:
> The problem that I have is that xsd does not
> accept the xsd schema files that I have provided, or sometimes it
> accepts them but the generated source code does not compile.
>   
A tip that might be of help if you want to hand write your schema:
I find it easier to first write the schema as relaxng and then convert 
it to an xml schema.

Some links:
http://www.thaiopensource.com/relaxng/trang.html
http://relaxng.org/tutorial-20011203.html
http://en.wikipedia.org/wiki/RELAX_NG

An example:

$ cd /tmp
$ cat /tmp/file.rng
<element name="book" xmlns="http://relaxng.org/ns/structure/1.0">
   <oneOrMore>
      <element name="page">
         <text/>
      </element>
   </oneOrMore>
</element>
$ wget http://jing-trang.googlecode.com/files/trang-20081028.zip
$ unzip trang-20081028.zip
$ java -jar /tmp/trang-20081028/trang.jar file.rng file.xsd
$ cat file.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
elementFormDefault="qualified">
  <xs:element name="book">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="page"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="page" type="xs:string"/>
</xs:schema>


You could validate an xml file to these scemata by these commands
$ xmllint --relaxng file.rng file.xml
$ xmllint --schema file.xsd file.xml

cheers,
Erik Sjölund



More information about the xsd-users mailing list