Datasheet

There’s a separate mechanism for associating a schema with a document that has no namespace
(xsi:noNamespaceSchemaLocation). For completeness, here’s the XML Schema document that describes
book.xml.
1: <?xml version="1.0" encoding="UTF-8"?>
2: <xs:schema
3: targetNamespace="http://sauria.com/schemas/apache-xml-book/book"
4: xmlns:book="http://sauria.com/schemas/apache-xml-book/book"
5: xmlns:xs="http://www.w3.org/2001/XMLSchema"
6: elementFormDefault="qualified">
7: <xs:element name="address" type="xs:string"/>
8: <xs:element name="author" type="xs:string"/>
9: <xs:element name="book">
10: <xs:complexType>
11: <xs:sequence>
12: <xs:element ref="book:title"/>
13: <xs:element ref="book:author"/>
14: <xs:element ref="book:isbn"/>
15: <xs:element ref="book:month"/>
16: <xs:element ref="book:year"/>
17: <xs:element ref="book:publisher"/>
18: <xs:element ref="book:address"/>
19: </xs:sequence>
20: <xs:attribute name="version" type="xs:string" use="required"/>
21:
22: </xs:complexType>
23: </xs:element>
24: <xs:element name="isbn" type="xs:string"/>
25: <xs:element name="month" type="xs:string"/>
26: <xs:element name="publisher" type="xs:string"/>
27: <xs:element name="title" type="xs:string"/>
28: <xs:element name="year" type="xs:short"/>
29: </xs:schema>
Entities
The example document is a single file; in XML terminology, it’s a single entity. Entities correspond to
units of storage for XML documents or portions of XML documents, like the DTD. Not only is an XML
document a tree of elements, it can be a tree of entities as well. It’s important to keep this in mind
because entity expansion and retrieval of remote entities can be the source of unexpected performance
problems. Network fetches of DTDs or a common library of entity definitions can cause intermittent per-
formance problems. Using entities to represent large blocks of data can lead to documents that look rea-
sonable in size but that blow up when the entities are expanded. Keep these issues in mind if you’re
going to use entities in your documents.
XML Parser APIs
Now that we’ve finished the XML refresher, let’s take a quick trip through the two major parser APIs:
SAX and DOM. A third parser API, the STreaming API for XML (STAX), is currently making its way
through the Java Community Process (JCP).
6
Chapter 1
01 543555 Ch01.qxd 11/5/03 9:40 AM Page 6