XML is simple, flexible, descriptive, accessible, independent, precise, and free! Using it in Flash will save you maintenance time. What more incentive could you need to start working with it?
Youve seen the advantages that XML offers over HTML and XHTML when working with structured data. Given the strong support for XML in Flash, theres bound to be some project in the near future where youll need to use XML data.
The rules for creating XML documents are simple. You just need a text editor or another software package capable of generating XML. The only proviso is that you follow some basic rules so that the XML document is well formed .
Reading an XML document is also simple. Tag names are normally descriptive so you can figure out what data each element contains. The hierarchical structure of elements allows you to work out the relationships between each piece of information. When you use XML documents, you dont have to separate out extra style elements when reading an XML document.
One key aspect of XML is its flexibility. As long as you follow some simple rules, you can structure an XML document in any way you like. The choice of tag names, attributes, and structures is completely flexible so you can tailor it to suit your data.
Unless youre working with an existing XML-based language such as XHTML, you are not restricted to a standard list of tags. For example, in XHTML, you have to use an <h1> tag to display a title on your web page; you cant create your own tag <pageTitle> .
You can share information about your XML-based language with other people by using a DTD or schema to describe the grammar, or rules, for the language. While both types of documents serve the same purpose, schemas use XML to describe the syntax. So if you know XML, you know the basic rules for writing schemas.
Software programs can also use DTDs and schemas. This allows them to map XML elements and work with specific parts of XML documents. For example, Excel 2003 for PCs uses schemas when exporting XML documents. The schema describes the name for each tag, the type of data it will contain, and the relationships among each of the elements.
XML documents provide data for use in different applications. You can generate an XML document from a corporate software package, transform it to display on a website, share it with staff on portable devices, use it to create PDF files, and provide it to other software packages. You can reuse the same data in several different settings. The ability to repurpose information is one of XMLs key strengths.
The way XML information displays is also flexible. You can display any XML document in a web browser to see the structure of elements. You can also use other technologies or software packages to change the display quite dramatically. For example, you could transform your phone book XML document into
A printed list of names and numbers sorted into name order
A web page displaying the full details of each entry in a table
A Flash movie that allows you to search for a contact
Im sure you can think of many more ways to use a phone book XML document.
Because you can choose your own tag names, your XML document becomes a description of your data. Some people call XML documents self-describing .
Its easy for humans to understand the content of an XML document just by looking at the tag names. Its also unambiguous for computers, providing they know the rules and structures in the XML document.
In our XHTML page, we could only describe each table cell using the tag <td> . The corresponding XML document used tags like <name> , <address> , and <phone> , so it was easy to determine what information each element contained.
The hierarchy in elements means that XML documents show relationships between information in a similar way to a database. The hierarchies in the phone book document tell me that each contact has a name, address, and phone number and that I can store many different contacts.
XML documents separate data from presentation so you can have access to the information without worrying about how it displays. This makes the data accessible to many different people, devices, and software packages at the same time. For example, my phone book XML document could be
Read aloud by a screen reader
Displayed on a website
Printed to a PDF file
Processed automatically by a software package
Viewed on a mobile phone
XML documents use Unicode for their standard character sets so you can write XML documents in any number of languages. A Flash application could offer multilingual support simply by using different XML documents within the same movie. Switch to a different XML document to display content in an alternative language. The Le@rning Federation example referred to in Chapter 1 does exactly that.
XML is platform and device independent. It doesnt matter if you view the data on a PC, Macintosh, or handheld computer. The data is still the same and people can exchange it seamlessly. Programmers can also use XML to share information between software packages that otherwise couldnt communicate with each other.
You dont need a specific software package to work with XML documents. You can type the content in just about any package capable of receiving text. The document can be read in a web browser, text editor, or any other XML processor. XML documents can query databases to provide a text-based alternative. In the case of web services, XML is an intermediary between you and someone elses database.
XML doesnt have flavors that are specific to a single web browser, version, or operating system. You dont have to create three different versions of your XML document to cater for different viewing conditions.
XML is a precise standard. If you want your XML document to be read by an XML parser, it must be well formed. Documents that arent well formed wont display. Compare this with HTML files. Even when it contains fundamental errors, the web page will still display in a web browser.
When a schema or DTD is included within an XML document, you can validate the content to make sure that the structure conforms to the rules youve set down. Less strict languages like HTML dont allow you to be this precise with your content. XML documents with schemas provide standards so there is only one way that the data they contain can be structured and interpreted.
XML is a specification that isnt owned by any company or commercial enterprise. This means that its free to use XMLyou dont have to buy any special software or other technology. In fact, most major software packages either support XML or are moving so that they will support it in the future.
XML is a central standard in a whole family of related standards. These recommendations work together to create an independent framework for managing markup languages. Table 2-2 shows some of the other related recommendations from the W3C.
XML Schema Definition (XSD)
Schemas describe the structure and syntax of an XML document.
Extensible Stylesheet Language (XSL)
XSL determines the presentation of XML documents. It uses XSL Transformations (XSLT), XML Path Language, and XSL Formatting Objects (XSL-FO).
XSL Transformations (XSLT)
XSLT transforms one XML document into another XML document.
XML Path Language (XPath)
XPath navigates or locates specific parts of XML documents.
XSL Formatting Objects (XSL-FO)
XSL-FO specifies formatting to be applied to an XML document.
XML Linking Language (XLink)
XLink describes the links between XML documents.
XML Pointer Language (XPointer)
XPointer describes references between XML documents so you can use them in links or in other documents.
XML Query (XQuery)
XQuery queries XML documents to extract information. At the time of writing, it was a working draft rather than a recommendation of the W3C.
XForms are an XML-based replacement for XHTML forms.
Simple Object Access Protocol (SOAP)
SOAP is a standard protocol for requesting information from a web service.
Web Services Description Language (WSDL)
WSDL describes web services using an XML structure.
Ill look a little more closely at DTDs, XML schemas, and XSLT in Chapter 3 of this book.