65

I have a DTD that I need to convert to an XSD (XML schema) file. Is there a free utility or simple way to accomplish this?

DVK
  • 126,886
  • 32
  • 213
  • 327
Jeremy Stein
  • 19,171
  • 16
  • 68
  • 83

4 Answers4

57

If you happen to have Visual Studio, open the DTD file an you should have a button to "Create Schema" out of it.
I haven't checked if it was available on Express edition, though.

Serge
  • 6,554
  • 5
  • 30
  • 56
45

The W3C offers one. There are also online converters.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
  • 10
    The 'online converters' XML Utilities link is currently out-of-date. The tool moved to: [http://www.xmlutilities.net](http://www.xmlutilities.net). But now you'll have to request for access. I found a link to this tool [http://www.lumrix.net/dtd2xs.php](http://www.lumrix.net/dtd2xs.php) in an O'REILLY article and it worked well for me (you do need the Java Runtime Environment installed, but most of us still have that :-) ). – Maarten Docter Dec 04 '13 at 11:10
  • 4
    lumrix.net tool also gone – Dr. Max Völkel Dec 31 '14 at 10:19
  • 3
    Good things disappear quickly from the internet. – IS4 May 10 '16 at 20:36
  • There is another version of the W3C tool here http://www.mathling.com/xmlschema/ . Found it here: http://edutechwiki.unige.ch/en/XML_Schema#DTD_to_XSD_Conversion_tools – MeTTeO Aug 22 '16 at 19:37
  • 1
    The lumrix.net link is also broken/out-of-date. A Google search on just "dtd2xs.php" turns up quite a few hits, but most are the same link, or sites that I was a little nervous about downloading from... – Peter Howe Sep 28 '16 at 12:06
  • Does JDK have command line tool from DTD to XSD conversion? – Andriy Kryvtsun Jan 25 '17 at 16:46
  • 1
    The lumrix dtd2xs tool (Java) can be found here: https://github.com/reposit/dtd2xs This worked for me: `java -cp . dtd2xsd report.dtd > report.xsd` – seanf Feb 02 '17 at 14:00
  • W3C tool requires ***Perl installation*** – Kiquenet Oct 30 '17 at 13:08
  • 1
    the w3c one is actually broken, I guess it is too old. it generates invalid xsd. – Wang May 16 '21 at 09:36
13

Try xmlpad from https://download.cnet.com/XmlPad/3000-7241_4-10252051.html to convert DTD to XSD. Really nice tool.

Sean Duggan
  • 1,105
  • 2
  • 18
  • 48
asingh
  • 157
  • 2
  • 5
12

http://www.thaiopensource.com/relaxng/trang.html

Trang converts between different schema languages for XML. It supports the following languages:

  • RELAX NG (XML syntax)
  • RELAX NG compact syntax
  • XML 1.0 DTDs
  • W3C XML Schema

http://www.thaiopensource.com/relaxng/trang-manual.html

Andriy Plokhotnyuk
  • 7,883
  • 2
  • 44
  • 68