Search This Blog

Monday, August 16, 2010

Chapter 8: XML

XML—eXtensible Markup Language—is a relatively recent innovation. It was originally designed to be a human-readable means of exchanging structured data, and yet it has gained ground very quickly as a means of storing structured data as well. Although XML is different from databases in many ways, both are methods of formatting/storing structured data persistently, and both have advantages and drawbacks.


XML isn't really a language but instead is a specification for creating your own markup languages. It is a subset of Standard Generalized Markup Language (SGML, the parent of HTML). XML is intended to allow easy exchange of data between disparate applications. If you read an XML document (and are familiar with HTML) you'll notice similarities in the way HTML and XML documents are formatted. Although HTML has a fixed set of elements and attributes defined in the HTML specification, XML enables you to write your own elements and attributes, thereby providing the capability to define your own language in XML or to use someone else's definition. Essentially, you can format any data you wish using XML.


In addition, XML provides facilities for making the data definition available, in a readable format, to any other application online. So an application that knows nothing about your application can still exchange data as long as both applications have XML parsing capability.


For these reasons XML is rapidly becoming the data exchange standard, and PHP5 has many new features and functions that make working with XML data fast and efficient, as well as more intuitive. PHP5 includes all the XML functions found in PHP4, as well as new functions based on simpleXML (a built-in PHP extension that supports common XML operations).


In this chapter you learn XML basics as well as how to read and write XML documents with an xml parser and with simpleXML functions. You also examine the Document Object Model (DOM) and learn how XML is utilized in Web services. Finally, you manipulate XML documents with simpleXML functions.