DTD or XML Schema. Which one is better?

What are the pros and cons in DTD and XML schemas (I'm not even sure what the official name of the latter is!)? What's better? Why do we need two ways to do the same thing?

Edit: I found this in an article I read, and this prompted me to ask a question:

Why is the W3C XML Schema Language?

The W3C XML Schema Language is not just a schema language. In fact, the XML specification describes a document type (DTD) as a way to express a schema. In addition, preliminary versions of JAXB The reference implementation worked only with DTDs β€” that is, not with schemas written in the XML schema language. However, the XML schema language is much richer than DTD. For example, schemas written in an XML schema. A language can describe structural relationships and data types that cannot be expressed (or cannot be easily expressed) in a DTD. There are tools available for converting DTDs to the W3C XML Schema Language, so if you have DTD-based Schemas that you used with the earlier version of the JAXB Reference implementation, you can use these tools to convert the schemas to XML Schema Language. http://java.sun.com/developer/technicalArticles/WebServices/jaxb/#binsch

I think I would like to see examples illustrating why an XML schema is better (if it really is).

+30
xml xsd dtd
Sep 29 '09 at 4:34
source share
4 answers

From http://weblogs.asp.net/rchartier/archive/2006/03/21/440782.aspx

  • DTDs are not a namespace.

  • DTDs have #define , #include and #ifdef - or, less C-oriented, the ability to define abbreviations, external content, and some conditional parsing.

  • DTD describes the entire XML document (even if it leaves holes); a circuit can define parts.

  • XSD has a type system.

  • XSD has a much richer language for describing how an element or attribute looks. This is due to the type of system.

  • You can put inline DTD in an XML document, you cannot do it with XSD. This means that DTDs are safer (you only have to protect one bytestream - xml / dtd - and not
    multiple) .del>

  • The official definition of "valid XML" requires a DTD. Since this can be impractical, if not impossible, you often have to agree on the correctness of the scheme, which is not exactly the same.

For its part, it’s quite simple to write a validator for some XML if you have an XSD. I have not seen this with DTD, although I am sure that it exists.

+22
Sep 29 '09 at 4:42
source share

A few years ago there were reasons to use DTD on top of the XML schema (this was more common or better supported by XML tools). However, today I see no reason not to use XML Schema instead of DTD: XML Schema is much more efficient.

However, the XML schema is far from ideal (just try reading the specification or the book on the XML schema ...), and many alternatives have been developed since then (Schematron, Examplotron, RelaxNG). They may have technical advantages over XML Schema, but XML Schema is so common today that I see very few cases where an alternative would make sense.

+10
Oct 27 '09 at 16:05
source share

XML Schema can perform more complex validations. For example, if a DTD can check if the data type of an XML element is integer or string. While the XML schema can perform more complex checks, for example, if the xml element is a string starting with an uppercase letter or a positive integer. Finally, the XML schema uses XML syntax and its natural choice for developing web services.

+5
Dec 22 '09 at 11:51
source share

There is also Relax NG, another powerful language for validating XML documents, as well as Schematron and other technologies from DSDL . Relax NG is very simple and has a user-friendly form - Relax NG Compact, which allows you to write circuits similar to BNF circuits.

+4
Sep 29 '09 at 5:28
source share



All Articles