public final class DOMWalker extends Object
Constructor and Description |
---|
DOMWalker(InputStream xml)
Creates a walker for traversing a DOM document read from the given
input stream.
|
Modifier and Type | Method and Description |
---|---|
boolean |
enterElement(String name)
Enters the named child element.
|
String |
getAttribute(String name)
Returns the value of the named attribute of the current element.
|
String |
getContent()
Returns the text content of the current element.
|
String |
getName()
Returns the name of the current element.
|
Properties |
getNamespaces()
Returns the namespace mappings defined in the current element.
|
boolean |
iterateElements(String name)
Iterates through the named child elements over multiple calls.
|
void |
leaveElement()
Leaves the current element.
|
public DOMWalker(InputStream xml) throws IOException
xml
- XML input streamIOException
- if a document cannot be read from the streampublic Properties getNamespaces()
xmlns
attributes of the
current element.public String getName()
public String getAttribute(String name)
name
- attribute namenull
if not foundpublic String getContent()
public boolean enterElement(String name)
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(); }
name
- child element nametrue
if the element was entered,
false
otherwisepublic void leaveElement()
enterElement(String)
public boolean iterateElements(String name)
DOMWalker walker = ...; while (walker.iterateElements("...")) { ...; }
WARNING: This method should only be used when
walker.getName()
does not equal name
when
the while loop is started. Otherwise the walker will not be positioned
at the same node when the while loop ends.
name
- name of the iterated elementstrue
if another iterated element was entered, or
false
if no more iterated elements were found
and the original element is restored as the current elementCopyright © 2004-2020 The Apache Software Foundation. All Rights Reserved.