Showing posts with label dtd. Show all posts
Showing posts with label dtd. Show all posts

Sunday, January 17, 2010

Trang: DTD to XSD conversion

This morning, I was playing with James Clark's utility which can do conversion between different XML Schema languages.

The utility is, Trang and it's described at:
http://www.thaiopensource.com/relaxng/trang.html

Here's a little example I tried with Trang (a DTD to XSD conversion).

DTD input:
  <!ELEMENT note (to,from,heading,body)>
  <!ELEMENT to (#PCDATA)>
  <!ELEMENT from (#PCDATA)>
  <!ELEMENT heading (#PCDATA)>
  <!ELEMENT body (#PCDATA)>

Here's the XSD output I got from, Trang:
  <?xml version="1.0" encoding="UTF-8"?>
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="note">
      <xs:complexType>
        <xs:sequence>
          <xs:element ref="to"/>
          <xs:element ref="from"/>
          <xs:element ref="heading"/>
          <xs:element ref="body"/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>
    <xs:element name="to" type="xs:string"/>
    <xs:element name="from" type="xs:string"/>
    <xs:element name="heading" type="xs:string"/>
    <xs:element name="body" type="xs:string"/>
  </xs:schema>

As per Trang documentation, following combination of conversions are possible:
RELAX NG (both XML and compact syntax) & DTD
to
RELAX NG (both XML and compact syntax), DTD & XSD

I found this good, and can recommend this.