SAX/DOM Examples

Generating a Document Programmatically

The following two examples illustrate how to generate an XML document, using the SAX2 and DOM Level 2 APIs. The following XML document contains most of the core information items defined by the Infoset (including elements, attributes, characters, processing instructions, and namespace declarations), as well as a peripheral item, in this case a comment.

<?xml version="1.0"?>
<?order alpha ascending?>
<art xmlns='urn:art-org:art'>
  <period name="Renaissance"
          xmlns:a='urn:art-org:artists'>
    <a:artist>Leonardo da Vinci</a:artist>
    <a:artist>Michelangelo</a:artist>
    <a:artist>Donatello</a:artist>
  </period>
  <!-- insert period here -->
</art>

SAX2 Example

The following sample Java code illustrates ...

Get Essential XML: Beyond Markup now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.