Skip to main content

Beginning XML, 2nd Edition

Beginning XML, 2nd Edition

David Hunter, Kurt Cagle, Chris Dix, Roger Kovack, Jonathan Pinnock, Jeff Rafter

ISBN: 978-0-764-54394-4

Dec 2001

900 pages

Select type: Paperback

Product not available for purchase


What is this book about?

Extensible Markup Language (XML) is a rapidly maturing technology with powerful real-world applications, particularly for the management, display, and organization of data. Together with its many related technologies it is an essential technology for anyone using markup languages on the web or internally.

This book teaches you all you need to know about XML — what it is, how it works, what technologies surround it, and how it can best be used in a variety of situations, from simple data transfer to using XML in your web pages. It builds on the strengths of the first edition, and provides new material to reflect the changes in the XML landscape — notably SOAP and Web Services, and the publication of the XML Schemas Recommendation by the W3C.

What does this book cover?

Here are just a few of the things this book covers:

  • XML syntax and writing well-formed XML
  • Using XML Namespaces
  • Transforming XML into other formats with XSLT
  • XPath and XPointer for locating specific XML data
  • XML Validation using DTDs and XML Schemas
  • Manipulating XML documents with the DOM and SAX 2.0
  • SOAP and Web Services
  • Displaying XML using CSS and XSL
  • Incorporating XML into tradition databases and n-tier architectures
  • XLink and XPointer for linking XML and non-XML resources

Who is this book for?

Beginning XML, 2nd Edition is for any developer who is interested in learning to use XML in web, e-commerce or data-storage applications. Some knowledge of mark up, scripting, and/or object oriented programming languages is advantageous, but not essential, as the basis of these techniques are explained as required.

Related Resources


Contact your Rep for all inquiries


Chapter 1: What is XML?

Chapter 2: Well-Formed XML.

Chapter 3: XML Namespaces.

Chapter 4: XSLT.

Chapter 5: Document Type Definitions.

Chapter 6: XML Schemas.

Chapter 7: Advanced XML Schemas.

Chapter 8: The Document Object Model (DOM).

Chapter 9: The Simple API for XML (SAX).

Chapter 10: SOAP.

Chapter 11: Displaying XML.

Chapter 12: XML and Databases.

Chapter 13: Linking and Querying XML.

Case Study 1: Using XSLT to Build Interactive Web Applications.

Case Study 2 - XML Web Services.

Appendix A: The XML Document Object Model.

Appendix B: XPath Reference.

Appendix C: XSLT Reference.

Appendix D: Schema Element and Attribute Reference.

Appendix E: Schema Datatypes Reference.

Appendix F: SAX 2.0: The Simple API for XML.

Appendix G: Useful Web Resources.


Download source code for this book
ChapterPageDetailsDatePrint Run
42Adding Attributes to Als CD

In this example, the code and the screenshot do not agree. Single quotes are used around the values of the attributes we are asked to add in the code but double quotes appear in the screenshot. As either single or double quotes are acceptable for attributes, either can be used but IE will display whichever you use in the code ordinarily.

Also, the How It Works for this example on Page 43 describes adding the first attribute without quotes and then receiving an error message in IE as the parser finds this error - this step is not described in the Try It Out section.

Thanks to Howard for spotting this.


49Incorrect Screenshot

The screenshot on page 49 is incorrect and does not represent how the file cd4.xml will look when viewed with Internet Explorer 5 or later. It is the one on page 47 repeated.

The correct screenshot (named cd4xml.jpg) is available within the code download for this book.

It shows the inclusion of the and elements.

Thanks to Silhone Sung


84Unseen members of namespaces list

At the top of page 84 we give a list of namespaces and introduce them as having been seen before in the chapter. In fact, only the pers namespace has been seen before.

The text surrounding the list can be reworded to read:

Imagine we choose to create three namespaces for Serna Ferna Inc:

  • http//

We could instead create one namespace which the company would use for all of its XML document types. Or, conversely, we could break down or namespaces down further, perhaps splitting the <person> document type into multiple namespaces. Why did we choose three?


488Incorrect URL for the Java Version of Xalan

The correct URL for the download of Xalan for Java is:

Thanks to Shannon Bain for spotting this.


94"given" should be "quantity"

The second paragraph on page 94 incorrectly states that the template shown on page 93 will be applied for any elements named given . In fact it should be quantity .

The sentence should read:

In this case, the template will be applied for any elements.


94Incorrect example

The explanation of the example given to illustrate the use of the <xsl:value-of> element does not agree with the example code. The code uses the <quantity> element, whereas the explanation uses <first>.

The correct explanation should read:

In other words, if the XSLT engine finds:


it will output 16, and if it finds:


it will output 121


94Incorrect backwards reference to CSS

In the 'Associating Stylesheets with XML Documents Using Processing Instructions' section, there is an erroneous backwards reference to CSS. At this stage in the book we haven't covered this in detail (please see Chapter 11 where this discussion does take place).

The sentence that begins 'However, an XSL stylesheet...' should read:

However, an XSL stylesheet can also be associated with an XML document using a processing instruction, like this:


4104Incorrect font used

The formatting of the last 2 words on the page should have been the other way around. At present, the word axis is formatted to indicate that it is the name of an axis when, in fact, the name of the axis is attribute.

Thanks to Jeff Wofford for pointing this out.


111Missing closing slashes

In both code fragments in the <xsl:apply-templates> section of the page, the <xsl:apply-templates> elements are missing the closing slash required to make the fragments well formed XML.

In the first fragment, the element should read:


and in the second fragment, the element should read:

<xsl:apply-templates select= item />


4127Header missing from ElemsToAtts.xsl

The line is missing from the top of the ElemsToAtts.xsl stylesheet created in stage 4 of the Try It Out example.

Although the stylesheet will still work in MSXSL, it is important to note that it may not work elsewhere as the omission of this line makes the it not well formed.

Thanks to Jeff Wooford for spotting this.


131Location of order.xml code

The code for order.xml is shown on pages 99-100, but it's easy to miss as it's not used in any Try It Out example until we get to this page.
Also, when you run the example on page 131 with order.xml, you'll notice that there are some errors on the page. The command to run the example should be

>msxsl order.xml defaulttemplates.xsl

in both cases, rather than

>msxsl order.xml defaults.xsl

When you run the code the first time, the resulting output will include Company A, rather than Customer A, as this is the data contained in order.xml.

When you run the code the second time, the resulting output will include Customer: Company A, rather than Customer: Customer A, as this is the data contained in order.xml.


132Try It Out - Default Template Gotchas

n step 3, the command to run the file should be:

>msxsl order.xml defaulttemplates.xsl

and the results should show:

Company A rather than Customer A

In step 4, the command to run the file should be:

>msxsl order.xml defaulttemplates.xsl

and the results should show:

Customer: Company A rather than Customer: Customer A


134Erroneous element in code

The code for the <xsl:choose> example does not match the text. The code shows the use of the <salary> element rather than the <number> element discussed.

The code should read:

<xsl:when text=number[number(.)...
<xsl:when text=number[number(.)...

Thanks to Marianne Hazlewood for spotting this.


4140Wrong function name in stylesheet

On page 123 the stylesheet AttsToElems.xsl is shown. This stylesheet is reshown on page 140, however there is a difference. In the last template of the stylesheet on page 123 the local-name() function is used, but in the last template of the same stylesheet on page 140 the name() function is used. This should still work but the name should not have changed from page 123. Thanks to Michael O' Sullivan for bringing this to our attention


194Incorrect NMTOKENS example

The first line of code on page 194 should read:




Thanks to Don Foster


260Incorrect example for date datatype

The value 05-07-1995 has been given as a valid example of date datatype value.

This is incorrect because the date datatype uses the format CCYY-MM-DD. The correct example should be 1995-05-07

Thanks to Matt Howell


278Extending simpleType Definitions

The second of the examples showing valid code according to the element declaration earlier in the page contains an error - the attribute name, gender, is missing.

It reads: <artist = male > Weird Al Yankovic</artist>

But it should read:

<artist gender= male > Weird Al Yankovic</artist>


7293Incorrect Namespace Prefix

Page 293 shows the following code snippet: <artist title= Mr > <name:first>Alfred</name:first> <name:middle>middle</name:middle> <name:last>Yankovic</name:last> </artist> The namespace prefix of name: used here is incorrect. This namespace prefix is declared in the root element of the instance document as n: and not name: so this code snippet should be: <artist title= Mr > <n:first>Alfred</n:first> <n:middle>middle</n:middle> <n:last>Yankovic</n:last> </artist> Note that this also means the very last sentence at the bottom of the page needs the reference to the 'name' prefix changed to n. In other words this last sentence should read: 'therefore we must qualify them with the n prefix we declared in the root element of our instance document'. Thank you Michael O' Sullivan for bringing this to our attention.


324Incorrect Screenshot

Unfortunately the first screenshot on this page is a repeat of the second one.

The first screenshot should show the text DemoElement rather than null.


353Minimal Parsing Using Sax

In the Try It Out section beginning on page 352 the java listing in step 2 fails to include the statement:

import org.xml.sax.helpers.XMLReaderFactory;

This results in a compile time error. This is corrected in the full listing that follows on page 354 - 355 and in the file available from the code download.

In step 4 a semi-colon is missing from the end of the statement:

XMLReader readerObj = XMLReaderFactory.createXMLReader ( org.apache.xerces.parsers.SAXParser )

This results in a compile time error. This is also corrected in the full listing that follows on page 354 - 355 and in available in the code download.

Thanks to Nat Thompson for pointing out these omissions.


441em should be i

The second code block on the page does not correspond with the first. It shows the use of em in a container relationship, instead of i . The code should read:

h1 i {color:red}

Also, the reference to <em> in the following sentence should be to <i>.


476Incorrect field name in diagram

In the first diagram on the page, which shows the CorporateCustomer table, the third field name is incorrect.

The diagram shows company_name, but should show company_address.


552Running the Address Book Application and Tomcat 4.0.2

Unfortunately, the latest release of Tomcat, Tomcat 4.0.2, has changed XML parsing capabilities and class loading methods from the release that was current at the time the book was written. This means that if you have Tomcat 4.0.2 you will need to carry out some extra steps in order to run the address book application sucessfully (this is because the code was designed to run with an earlier version).

If you don't carry out the extra steps, you will recieve internal server errors when trying to run the application.

You will need to:

*Install Tomcat as instructed in the book, including setting the JAVA_HOME environment variable.
*Copy the xsl.war file to the webapps directory, as instructed in the book.
*Start Tomcat to enable unpacking of the .war file.
*Stop Tomcat.
*Within the Tomcat files, move xerces.jar from common/lib to server/lib (i.e. there shouldn't be a copy of xerces.jar in common/lib anymore and there should be one in server/lib).
*Within the case study application files move crimson.jar and saxon.jar from xsl/WEB_INF/lib to common/lib in the Tomcat files (i.e. there shouldn't be copies of crimson.jar and saxon.jar in xsl/WEB_INF/lib anymore and there should be copies of them in common/lib).
*Start Tomcat again.
*Type http://localhost:8080/xsl/xslapp into your browser and the application should start fine.