- XML Reference Guide
- Overview
- What Is XML?
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Table of Contents
- The Document Object Model
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- DOM and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Implementations
- DOM and JavaScript
- Using a Repeater
- Repeaters and XML
- Repeater Resources
- DOM and .NET
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Downloads
- DOM and C++
- DOM and C++ Resources
- DOM and Perl
- DOM and Perl Resources
- DOM and PHP
- DOM and PHP Resources
- DOM Level 3
- DOM Level 3 Core
- DOM Level 3 Load and Save
- DOM Level 3 XPath
- DOM Level 3 Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- The Simple API for XML (SAX)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SAX and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- SAX and .NET
- Informit Articles and Sample Chapters
- SAX and Perl
- SAX and Perl Resources
- SAX and PHP
- SAX and PHP Resources
- Validation
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Document Type Definitions (DTDs)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Schemas
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- RELAX NG
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Schematron
- Official Documentation and Implementations
- Validation in Applications
- Informit Articles and Sample Chapters
- Books and e-Books
- XSL Transformations (XSLT)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XSLT in Java
- Java in XSLT Resources
- XSLT and RSS in .NET
- XSLT and RSS in .NET Resources
- XSL-FO
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XPath
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XML Base
- Informit Articles and Sample Chapters
- Official Documentation
- XHTML
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XHTML 2.0
- Documentation
- Cascading Style Sheets
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XUL
- XUL References
- XML Events
- XML Events Resources
- XML Data Binding
- Informit Articles and Sample Chapters
- Books and e-Books
- Specifications
- Implementations
- XML and Databases
- Informit Articles and Sample Chapters
- Books and e-Books
- Online Resources
- Official Documentation
- SQL Server and FOR XML
- Informit Articles and Sample Chapters
- Books and e-Books
- Documentation and Implementations
- Service Oriented Architecture
- Web Services
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Creating a Perl Web Service Client
- SOAP::Lite
- Amazon Web Services
- Creating the Movable Type Plug-in
- Perl, Amazon, and Movable Type Resources
- Apache Axis2
- REST
- REST Resources
- SOAP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- SOAP and Java
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- WSDL
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- UDDI
- UDDI Resources
- XML-RPC
- XML-RPC in PHP
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Ajax
- Asynchronous Javascript
- Client-side XSLT
- SAJAX and PHP
- Ajax Resources
- JSON
- Ruby on Rails
- Creating Objects
- Ruby Basics: Arrays and Other Sundry Bits
- Ruby Basics: Iterators and Persistence
- Starting on the Rails
- Rails and Databases
- Rails: Ajax and Partials
- Rails Resources
- Web Services Security
- Web Services Security Resources
- SAML
- Informit Articles and Sample Chapters
- Books and e-Books
- Specification and Implementation
- XML Digital Signatures
- XML Digital Signatures Resources
- XML Key Management Services
- Resources for XML Key Management Services
- Internationalization
- Resources
- Grid Computing
- Grid Resources
- Web Services Resource Framework
- Web Services Resource Framework Resources
- WS-Addressing
- WS-Addressing Resources
- WS-Notifications
- New Languages: XML in Use
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Google Web Toolkit
- GWT Basic Interactivity
- Google Sitemaps
- Google Sitemaps Resources
- Accessibility
- Web Accessibility
- XML Accessibility
- Accessibility Resources
- The Semantic Web
- Defining a New Ontology
- OWL: Web Ontology Language
- Semantic Web Resources
- Google Base
- Microformats
- StructuredBlogging
- Live Clipboard
- WML
- XHTML-MP
- WML Resources
- Google Web Services
- Google Web Services API
- Google Web Services Resources
- The Yahoo! Web Services Interface
- Yahoo! Web Services and PHP
- Yahoo! Web Services Resources
- eBay REST API
- WordML
- WordML Part 2: Lists
- WordML Part 3: Tables
- WordML Resources
- DocBook
- Articles
- Books and e-Books
- Official Documentation and Implementations
- XML Query
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- XForms
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Resource Description Framework (RDF)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Topic Maps
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation, Implementations, and Other Resources
- Rich Site Summary (RSS)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- Simple Sharing Extensions (SSE)
- Atom
- Podcasting
- Podcasting Resources
- Scalable Vector Graphics (SVG)
- Informit Articles and Sample Chapters
- Books and e-Books
- Official Documentation
- OPML
- OPML Resources
- Summary
- Projects
- JavaScript TimeTracker: JSON and PHP
- The Javascript Timetracker
- Refactoring to Javascript Objects
- Creating the Yahoo! Widget
- Web Mashup
- Google Maps
- Indeed Mashup
- Mashup Part 3: Putting It All Together
- Additional Resources
- Frequently Asked Questions About XML
- What's XML, and why should I use it?
- What's a well-formed document?
- What's the difference between XML and HTML?
- What's the difference between HTML and XHTML?
- Can I use XML in a browser?
- Should I use elements or attributes for my document?
- What's a namespace?
- Where can I get an XML parser?
- What's the difference between a well-formed document and a valid document?
- What's a validating parser?
- Should I use DOM or SAX for my application?
- How can I stop a SAX parser before it has parsed the entire document?
- 2005 Predictions
- 2006 Predictions
- Nick's Book Picks
A cousin of Hypertext Markup Language (HTML), Extensible Markup Language (XML) provides a human-readable, platform-independent way to represent data, whether it's content destined for a web page or brochure, or data destined for an enterprise database.
Like HTML and their mutual parent, Standard Generalized Markup Language (SGML), XML works on the principle of tags, which delineate elements and content. Consider, for example, the following XML document:
<?xml version="1.0"?> <candy> <product>Chocolate Bar</product> </candy>
This simple document has two elements: candy and product. These elements are indicated by tags, or constructions that start with the less-than sign (<) and end with the greater-than sign (>) surrounding the name of the element. In other words, the candy element starts with the candy opening tag:
<candy>
and ends with the candy closing tag:
</candy>
The slash (/) at the beginning indicates that it's a closing tag.
Because the product element is between the candy opening and closing tags of the candy element, it's said to be nested within the candy element.
XML elements frequently have attributes (name/value pairs that appear within the opening tag of the element). For example, in the following document, the product element is said to have a type attribute with a value of chocolate and an itemid attribute with a value of C33:
<?xml version="1.0"?> <candy> <product type="chocolate" itemid="C33">Harvey Bar</product> </candy>
If you're familiar with the specific set of elements and attributes you can play with in HTML, you may be a little surprised to find out that there are no such restrictions in XML itself. That's what makes it so powerful. Application developers and industries are free to create their own vocabularies, such as these:
Extensible Hypertext Markup Language (XHTML) is an XML version of HTML.
Scalable Vector Graphics (SVG) is a means for describing graphics via tags rather than binary information.
Business Process Markup Language (BPML) provides a way to describe the flow of information within an enterprise.
You might design an application that outputs order information like this:
<?xml version="1.0"?> <order orderid="THX1138" customerNumber="3263827"> <lineitem itemid="C33"> <quantity>36</quantity> <unitprice currency="dollars">.35</unitprice> </lineitem> <lineitem itemid="M48"> <quantity>1</quantity> <unitprice currency="dollars">2200</unitprice> </lineitem> </order>
This information could be destined for any number of systems. It might be transformed into a web page that acts as a receipt, or imported into a database of orders, or sent using a web service to a fulfillment house.
XML 1.0 is defined by the XML 1.0 Recommendation from the World Wide Web Consortium (W3C), and is used as the basis for a number of related specifications and recommendations.
XML documents must adhere to several "rules" in order to be considered well-formed:
They must have a single root element, to which all other elements and text belong.
All opening tags must have a matching closing tag.
NOTE
Unlike HTML, XML is case-sensitive; the case of the tags must match exactly.
All attribute values must be enclosed in single (') or double quotes (").
Elements must be properly nested. In other words, an element that starts within another element must end within that element.
An XML document must be well-formed, or it can't be processed.
Working programmatically with XML data requires the use of a parseran application that reads the document and breaks it into its component parts for interpretation according to a particular model.
XML also enables you to combine different types of data through the use of namespaces. Namespaces are a way to indicate, via a prefix in the element name, that an element or attribute belongs to a particular type of data. For example, consider the following simple style sheet, with transformation instructions shown in bold:
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/"> <html> <head><title>Message of the Day</title></head> <body> <p><xsl:value-of select="message"/></p> </body> </html> </xsl:template> </xsl:stylesheet>
The elements prefixed by xsl: give instructions to the XSLT processor (as discussed in the section on XSL Transformations), and those without the prefix should be passed through to the resulting document.
It's important to note that the namespace is defined by the xmlns: attribute. In this case, the namespace is actually http://www.w3.org/1999/XSL/Transform, and not xsl:. The xsl: notation is simply the prefix associated with the namespace. The document could just as easily have been done this way:
<?xml version="1.0"?> <bogus:stylesheet xmlns:bogus="http://www.w3.org/1999/XSL/Transform" version="1.0"> <bogus:template match="/"> <html> <head><title>Message of the Day</title></head> <body> <p><bogus:value-of select="message"/></p> </body> </html> </bogus:template> </bogus:stylesheet>