tags:

views:

336

answers:

4

i want to use one of these to describe my xml document.

i've read that xsd is better than the older dtd since it supports namespaces and data types.

does this mean that i should only use xsd for all future needs and totally ignore dtd and don´t even have to bother learning its structure?

+3  A: 

It wouldn't hurt to understand the structure of a DTD (it'll help you better understand an XSD in the long run)...but you should use XSDs moving forward.

Justin Niessner
+2  A: 

It really depends on how complicated the structure is that you need to setup.

If you need things like namespacing and datatypes, definitely go with XSD. If you just need a quick little schema to check against, DTD will give you faster performance since there is no XML parsing involved.

As I understand it, XSD is derived from DTD so understanding DTD will give a solid foundation for learning XSD, plus point out some of DTD's short comings.

Brant
+4  A: 

It's probably important to learn DTDs as a separate exercise, just for the knowledge of how they work in case you encounter them somewhere else, and so that you can appreciate some of the things that XSD was trying to solve.

However, for your current purposes of describing and XML document, indeed stick to XSDs.

In addition to having a far richer feature set (like you mention, including data types and namespaces), they are also XML documents themselves, which can be really useful. Because they are XML, you can check their well-formedness and validity a lot easier, and you can write code that works with them like regular XML files (for instance, if you wanted to autogenerate code classes from a schema)

Mike Mooney
A: 

No harm in learning DTD, but be sure to use XSD, because XSD has more strength,

With XSD you can not only validate the structure/hierarchy of the XML tags but also,

  1. You can define Data type of the values of the nodes. [date, number, string etc]
  2. You can also define custom data_types, [example, for node , the possible data can be one of the 12 months.. so you need to define all the 12 months in a new data type writing all the 12 month names as enumeration values .. validation shows error if the input XML contains any-other value than these 12 values .. ]
  3. You can put the restriction on the occurrence of the elements, using minOccurs and maxOccurs, the default values are 1 and 1.

.. and many more ...

There are some restrictions: as like,

  1. An element(name) defined in XSD file must be defined with only one data-type.
  2. You can't validate a node/attribute using the value of another node/attribute.
infant programmer