Zoo tutorials: [ SQL | Java | Linux | XML ]

A Gentle Introduction to xml

Introducing DOM
With answers

Question 1: getDocumentElement

http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/java-language-binding.html lists the properties and methods that should be available to you.

<?xml version="1.0" encoding="UTF-8" ?>
<stock andrew="was here">
  <item price="50" legend="Pr-Burger" BarCode="E1" />
  <item price="15" legend="Crisp S+V" BarCode="E5" />
  <item price="15" legend="Crisp C+O" BarCode="E6" />
  <item price="50" legend="Flat Cola" BarCode="E7" />
</stock>
The getDocumentElement() method returns the single top level node of the document. We can access the methods of the Element object and the methods inherited from the Node object.

Java DOM



Question 2: Node Lists

The method getElementsByTagName(t) is a handy method of Document. It returns a NodeList - this in turn has two methods item(i) and getLength()

Java DOM