Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. XML follows a specific format and helps give structure to data. Because XML is platform-neutral, computer-language-neutral, and text-based, it is useful for data exchange between computers and for data storage.
Example 16-15 displays a fragment from an XML document that shows how you might structure some simple data about a network device.
Example 16-15 XML Structure of a Network Device
<device>
<interface>mgmt0</interface>
<state>up</state>
<eth_ip_addr>192.168.10.175</eth_ip_addr>
<eth_ip_mask>24</eth_ip_mask>
<device>
The XML fragment has a root element called device. The device element has four child elements:
interface
state
eth_ip_addr
eth_ip_mask
You can think of each element as a data field. XML provides structure to those data fields. XML doesn’t do anything with the data. To manipulate that data, a piece of software has to send, receive, store, or display it. One example of such software is Google Postman.
Example
Example 16-16 displays an XML document that has a root node element called ciscopress. Notice that the ciscopress element contains one child element: book.
Example 16-16 XML Structure Example
<?xml version =”1.0″ encoding=”UTF-8″?>
<ciscopress>
<book isbn=”1587052024″>
<title>Routing TCP/IP</title>
<author>Jeff Doyle</author>
<category></category>
<year>2005</year>
<edition>2</edition>
<price>72</price>
</book>
</ciscopress>
Figure 16-2 shows a visual representation of the sample XML document as a tree.
Figure 16-2 Visual Representation of XML Document as a Tree
Note the following points:
The book element contains multiple child elements.
The book element contains metadata in the form of an attribute called isbn. An element can contain multiple attributes.
The <category> element in the sample XML document contains no character data. It’s an “empty element.” This is valid if the underlying schema allows it.
One aspect of the XML language that sets it apart from a markup language like HTML is that it has no predefined tags. The elements in Figure 16-2, such as <ciscopress> and <price>, are not defined in the XML standard. These elements and the document structure are created by the author of the XML document. That’s different from the way HTML works with predefined tags such as <p>, <h1>, and <table>.
An XML document that contains data is also sometimes referred to as an XML payload.
Leave a Reply