|
|
||
|
|
||
|
|
||
So far Ive introduced you to XML and given you some background information on how to construct XML documents. Youve also seen how XML is different from HTML and XHTML. Now its time to explore how you can use XML documents.
Remember that the primary purpose for XML documents is the storage of data. XML allows people to share information using a
An XML document is portable and doesnt require the purchase of any specific software or technology. You can use the same XML documents for many different purposes. Best of all, XML documents are completely platform independent.
Common uses for XML documents include
Storing and sharing information
Querying and consuming web services
Describing configuration settings
Interacting with databases
Interacting with Office 2003 documents
The most important use for XML documents is in storing information. XML documents provide a way to describe structured data within a text file. The advantage of XML over other storage formats is that it is a standard so you can use the same content in many different ways. The same XML file could provide content for a website, a Flash movie, and a printed document. You save time because you need to create the XML file only once to use it in these varied settings.
Each XML document that you create will probably have a different structure designed to meet the needs of the people or software who will use the information. The element
An XML document doesnt need any specific software or operating system, which means you can share it with other people and software applications. XML documents can also provide information to other web-based applications, including
If you are working in an industry
The listing that
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mrow>
<mi>sin</mi>
<mo>⁡</mo>
<mo>(</mo>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<mo>)</mo>
</mrow>
</math>
You can find out more about MathML at www.w3.org/Math/.
Another useful standard
The following listing shows a sample SVG document. Ive saved the document as
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/SVG/DTD/svg10.dtd"> <svg> <desc>Shapes</desc> <rect x="5" y="5" width="100" height="50" fill="yellow"/> <ellipse cx="200" cy="100" rx="100" ry="40" fill="blue"/> <polygon points="110,140 40,300 120,250" fill="green"/> </svg>
Figure 2-10 shows this file displayed in Internet Explorer.
Figure 2-10:
The sample SVG document displayed in Internet Explorer
XML documents are the standard way to share information through web services. Web services are public functions that organizations make available. For example, you can use web services to calculate currency exchange transactions, look up weather details, read news feeds, and perform searches at Amazon or Google.
When you send a request to a web service, youll often use SOAP, an XML format. Youll also receive the information from the web service in an XML document. Well look at web services in more detail later in this book.
Many software packages use XML documents to describe their configuration settings. For example, an XML document format is used to configure .NET applications. The settings for a .NET application are stored in a file called
web.config
. The file uses standard XML elements to store settings such as debugging, authentication, error handling, and global
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<appSettings>
<add key="fileSaveLocation" value="D:\Hosting\website\images\"/>
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true"/>
</system.web>
</configuration>
The file contains a global variable or key location for saving files: fileSaveLocation . There are also some settings for customized errors and debugging.
Many common databases allow you to work with XML documents. SQL Server and Oracle both offer support for XML interaction. XML documents can query a database and return results. For example, in SQL Server, you can construct a SELECT statement that returns the results as an XML fragment:
SELECT * FROM BOOKS FOR XML AUTO
XUpdate is an XML-based language that describes updates to an XML document tree. It is not a W3C recommendation but uses the XPath specification. XUpdate is one way to manage XML document and database updates. Flash uses
You can find out more about XUpdate at http://xmldb-org.
One exciting new application for XML is its role in Microsoft Office 2003 documents. For PC users, this means that you can save Word, Excel, and Access 2003 documents in XML format. Office 2003 can generate XML documents that you can use in other software packages, such as Flash. You can also display and update XML documents in Office 2003.
The Save As command converts Word and Excel 2003 documents into XML format using either WordprocessingML or SpreadsheetML . These are XML-based languages created by Microsoft to describe Word and Excel structures and formatting. You can also apply your own schema so that you can modify the XML documents produced by Office 2003.
Unfortunately, this functionality is only available for PC users. There is limited XML functionality in Excel 2004 for Macintosh users. Office XP for PCs also offers some XML support, but it is limited compared with Office 2003.