O'Reilly logo

Mastering Oracle SQL, 2nd Edition by Alan Beaulieu, Sanjay Mishra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 16. XML

Extensible Markup Language (XML) has become the standard mechanism for sharing data between applications. This chapter will explore how XML documents may be stored in an Oracle database, how the data within an XML document can be extracted and stored in relational tables, and how an XML document can be constructed from data in relational tables.

What Is XML?

XML is a close cousin to HTML, but while HTML is primarily concerned with formatting and displaying data, XML is concerned with the data itself. Unlike HTML, with XML you may create your own tags, which is why XML is perfectly suited for describing data. The easiest way to understand XML is through an example, so here is an XML document that represents a customer purchase order:

<?xml version="1.0"?>
<purchase_order>
  <customer_name>Alpha Technologies</customer_name>
  <po_number>11257</po_number>
  <po_date>2004-01-20</po_date>
  <po_items>
    <item>
      <part_number>AI5-4557</part_number>
      <quantity>20</quantity>
    </item>
    <item>
      <part_number>EI-T5-001</part_number>
      <quantity>12</quantity>
    </item>
  </po_items>
</purchase_order>

The first line defines that the text that follows is an XML document that adheres to Version 1.0 of the XML specification. The second line is the root node of the document and has the tag <purchase_order>. A valid XML document must contain exactly one root node. Other nodes of the document can appear more than once as necessary to describe the data, as illustrated by the multiple <item> tags under the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required