Skip to Content
Java and XML, 3rd Edition
book

Java and XML, 3rd Edition

by Brett McLaughlin, Justin Edelson
December 2006
Intermediate to advanced content levelIntermediate to advanced
479 pages
13h 52m
English
O'Reilly Media, Inc.
Content preview from Java and XML, 3rd Edition

Chapter 2. Constraints

It’s rare that you’ll be able to author XML without worrying about anyone else modifying your document, or anyone having to interpret the meaning of the document. The majority of the time, someone (or something) will have to figure out what your tags mean, what data is allowed within those tags, and how your document is structured. This is where constraint models come into play in the XML world. A constraint model defines the structure of your document and, to some degree, the data allowed within that structure.

In fact, if you take XML as being a data representation, you really can’t divorce a document (often called an instance) from its constraints (the schema). The instance document contains the data, and the schema gives form to that data. You can’t have one without the other; at least, not without introducing tremendous room for error. An instance document without a schema must be interpreted by the recipient; and do you really want him deciding what your elements and attributes meant?

Tip

There’s an argument that essentially goes like this: “Good XML should be structured so that it’s self-documenting.” That’s a good goal, but practically impossible. As a programmer, I often think my code is well documented and easily understood; but I’m assuming a certain level of expertise, and a certain approach to coding. Change just a few bits here and there, and someone else might reasonably interpret my “well-documented” code (or XML) completely differently than ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java & XML Data Binding

Java & XML Data Binding

Brett McLaughlin
Mastering Java 11 - Second Edition

Mastering Java 11 - Second Edition

Dr. Edward Lavieri Jr., Mandar Jog
XML in a Nutshell, 3rd Edition

XML in a Nutshell, 3rd Edition

Elliotte Rusty Harold, W. Scott Means

Publisher Resources

ISBN: 059610149XSupplemental ContentErrata Page