Welcome to New Horizons!

With 300 centers in 70 countries, New Horizons is the world’s largest independent IT training company. Our innovative, award-winning learning methods have revolutionized the way students learn, retain and apply new knowledge; and we offer the largest Guaranteed-to-Run course schedule in the world.

Our real-time, cloud-based lab solution allows students to access their labs anytime and anywhere. And we offer an extensive selection of vendor-authorized training and certifications for Microsoft, Cisco, CompTIA and VMware, ensuring that students are able to train on the latest products and technologies. Over our 30-year history, New Horizons has trained over 30 million people worldwide.

Manipulate the DOCTYPE to validate subsets of XML documents

A common misconception, especially among some folks with little XML experience, is that once you specify a DOCTYPE for a data set, that is the one you must always use, even if you're working with a subset of the document. This often leads to extracting the subset you want, adding upper level wrappers to match the DOCTYPE, and finagling things to get it to parse. Others will write custom DTDs to handle the subset.

It isn't necessary to jump through these hoops. Remember that the DOCTYPE declaration names the root element and points to the cooresponding DTD. The key here is that it points to the root element of the *document*, not the first element defined in the DTD.

For example, a journal DTD may define its upper content model like this:


So the DOCTYPE for the full data set would be:



However, say you want to send just a single article to a customer, but they want to be able to validate it against the DTD. You don't need to modify the DTD or add upper level wrappers to the article; just change the DOCTYPE from "journal" to "article".



It reads the same DTD, but only those elements which fall within the given DOCTYPE. It ignores the rest. That's all there is to it. This is true even if you include the DOCTYPE in the DTD itself; you can still specify a specific element to start parsing from. Print this post

0 comments: