Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
709 views
in Technique[技术] by (71.8m points)

xml - How to choose between DTD and XSD

I want to use either a DTD or an XSD to describe my XML document. I've read that XSDs are better than DTDs since they support namespaces and data types, and that DTDs are older.

Does this mean that I should only use XSDs for all future needs and totally ignore DTD as an option? Should I even bother learning the structure of DTDs?

What factors should I consider when choosing between XSD and DTD?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 an 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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...