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"
    <a:artist>Leonardo da Vinci</a:artist>
  <!-- insert period here -->

SAX2 Example

The following sample Java code illustrates ...

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

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