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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.