Home: www.vipan.com Vipan Singla e-mail: vipan@vipan.com
XML and XPath Usage

Most common DOM interfaces:

Common DOM methods

Document.getDocumentElement()
Returns the root "element" of the document. It is the top level tag in the document. It is different from the "root" itself which is just a "/". So the root element resides below the "/". There are other elements below the "/" such as an <xml> declaration or a "comment".
Node.getFirstChild() and Node.getLastChild()
Returns the first or last child of a given Node.
Node.getNextSibling() and Node.getPreviousSibling()
Return the next or previous element, node or whatever at the same level as the node itself in the document tree.
Node.getAttribute(attrName)
For a given Node, returns the attribute with the requested name. For example, if you want the Attr object for the attribute named id, use getAttribute("id").
getElementsByTagName("tag_name")
Retrieve all of the <tag_name> elements in the document. This method saves the trouble of writing code to traverse the entire tree. Or, you can use XPath. See below.

All Seven Kinds of Nodes

  1. The root
  2. Elements
  3. Text
  4. Attributes
  5. Namespaces
  6. Processing instructions
  7. Comments

XPath Abbreviated Syntax Examples

Demonstration Example of Using XML Xpath in a Java program

Core Functions

Each function in the function library is specified using a function prototype, which gives the return type, the name of the function, and the type of the arguments. If an argument type is followed by a question mark, then the argument is optional; otherwise, the argument is required.

Node-Set Functions

String Functions

Boolean Functions

Number Functions

Data Model


© Vipan Singla 2000