net.sf.exorcist.midgard
Class DOMWalker

java.lang.Object
  extended by net.sf.exorcist.midgard.DOMWalker

public final class DOMWalker
extends java.lang.Object

Document walker class. This class provides an intuitive interface for traversing a parsed DOM document.


Constructor Summary
DOMWalker(java.io.InputStream xml, java.lang.String namespace)
          Creates a walker for traversing a DOM document read from the given input stream.
 
Method Summary
 boolean enterElement(java.lang.String name)
          Enters the named child element.
 java.lang.String getAttribute(java.lang.String name)
          Returns the value of the named attribute of the current element.
 java.lang.String getContent()
          Returns the text content of the current element.
 java.lang.String getContent(java.lang.String name)
           
 java.lang.Object getCurrent()
           
 java.lang.String getName()
          Returns the name of the current element.
 java.util.Properties getNamespaces()
          Returns the namespace mappings defined in the current element.
 boolean iterateElements(java.lang.String name, java.lang.Object context)
          Iterates through the named child elements over multiple calls.
 void leaveElement()
          Leaves the current element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMWalker

public DOMWalker(java.io.InputStream xml,
                 java.lang.String namespace)
          throws java.io.IOException
Creates a walker for traversing a DOM document read from the given input stream. The root element of the document is set as the current element.

Parameters:
xml - XML input stream
Throws:
java.io.IOException - if a document cannot be read from the stream
Method Detail

getCurrent

public java.lang.Object getCurrent()

getNamespaces

public java.util.Properties getNamespaces()
Returns the namespace mappings defined in the current element. The returned property set contains the prefix to namespace mappings specified by the xmlns attributes of the current element.

Returns:
prefix to namespace mappings of the current element

getName

public java.lang.String getName()
Returns the name of the current element.

Returns:
element name

getAttribute

public java.lang.String getAttribute(java.lang.String name)
Returns the value of the named attribute of the current element.

Parameters:
name - attribute name
Returns:
attribute value, or null if not found

getContent

public java.lang.String getContent()
Returns the text content of the current element.

Returns:
text content

getContent

public java.lang.String getContent(java.lang.String name)

enterElement

public boolean enterElement(java.lang.String name)
Enters the named child element. If the named child element is found, then it is made the current element and true is returned. Otherwise the current element is not changed and false is returned.

The standard call sequence for this method is show below.

     DOMWalker walker = ...;
     if (walker.enterElement("...")) {
         ...;
         walker.leaveElement();
     }
 

Parameters:
name - child element name
Returns:
true if the element was entered, false otherwise

leaveElement

public void leaveElement()
Leaves the current element. The parent element is set as the new current element.

See Also:
enterElement(String)

iterateElements

public boolean iterateElements(java.lang.String name,
                               java.lang.Object context)
Iterates through the named child elements over multiple calls. This method makes it possible to use the following code to walk through all the child elements with the given name.
     DOMWalker walker = ...;
     while (walker.iterateElements("...")) {
         ...;
     }
 

Parameters:
name - name of the iterated elements
Returns:
true if another iterated element was entered, or false if no more iterated elements were found and the original element is restored as the current element


Copyright © 2005 The Exorcist Team @ SourceForge. All Rights Reserved.