Top Description Inners Fields Constructors Methods
groovy.xml.dom

public Class DOMCategory

extends Object
Class Inheritance
Imports
groovy.lang.Closure, .GroovyRuntimeException, .IntRange, groovy.xml.DOMBuilder, groovy.namespace.QName, org.apache.groovy.xml.extensions.XmlExtensions, org.codehaus.groovy.runtime.InvokerHelper, org.w3c.dom.Attr, .Document, .Element, .NamedNodeMap, .Node, .NodeList, .Text, javax.xml.xpath.XPath, .XPathExpressionException, .XPathFactory, java.util.ArrayList, .Collection, .Collections, .Iterator, .List, .Map

Category class which adds GPath style operations to Java's DOM classes.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static boolean
private static boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static void
addResult(List<E> results, Object result)

public static Element
public static Element
appendNode(Element self, Object name, Map<K, V> attributes)

public static Element
appendNode(Element self, Object name, String value)

public static Element
appendNode(Element self, Object name, Map<K, V> attributes, String value)

private static void
appendNodes(Node self, Closure<V> c)

public static NamedNodeMap
public static NodeList
public static NodeList
private static NodeList
public static NodeList
public static Object
get(Element element, String elementName)

public static Object
get(NodeList nodeList, String elementName)

public static Object
get(NamedNodeMap nodeMap, String elementName)

public static Node
getAt(Node o, int i)

public static Node
public static Node
public static NodeList
public static NodeList
public static NodeList
private static NodeList
getChildElements(Element self, String elementName)

private static NodeList
private static boolean
hasChildElements(Element self, String elementName)

public static boolean
public static synchronized boolean

Returns:

true if ignorable whitespace (e.g. whitespace between elements) is kept; default false
isGlobalKeepIgnorableWhitespace
()

public static synchronized boolean

Returns:

true if text elements are trimmed before returning; default false
isGlobalTrimWhitespace
()

public static List<Node>
list(NodeList self)

public static List<String>

Returns:

the list of String values from this node
localText
(Element self)

Returns the list of any direct String nodes of this node.

public static String
name(Node node)

private static Node
nodeGetAt(Object o, int i)

private static NodeList
public static Node
parent(Node node)

public static void
plus(Element self, Closure<V> c)

public static void
plus(NodeList self, Closure<V> c)

public static void
putAt(Element self, String property, Object value)

public static Node
public static Node
replaceNode(Node self, Closure<V> c)

public static synchronized void
setGlobalKeepIgnorableWhitespace(boolean
the new value
keepIgnorableWhitespace
)

Whether ignorable whitespace (e.g. whitespace between elements) is kept (default false).

public static synchronized void
setGlobalTrimWhitespace(boolean
the new value
trimWhitespace
)

Whether text content is trimmed (removing leading and trailing whitespace); default false.

public static void
setValue(Element self, String value)

public static int
size(NamedNodeMap namedNodeMap)

public static int
size(NodeList self)

public static String
text(Node node)

public static String
text(NodeList nodeList)

public static String
private static String
private static Object
xgetAt(Element element, String elementName)

private static Object
xgetAt(NodeList nodeList, String elementName)

private static String
xgetAt(NamedNodeMap namedNodeMap, String elementName)

private static Node
xgetAt(Element element, int i)

private static Node
xgetAt(NodeList nodeList, int i)

private static NodeList
xgetAt(Element element, IntRange r)

private static NodeList
xgetAt(NodeList nodeList, IntRange r)

public static Object
xpath(Node self, String expression, QName returnType)

public static String
xpath(Node self, String expression)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

keepIgnorableWhitespaceback to summary
private static boolean keepIgnorableWhitespace
trimWhitespaceback to summary
private static boolean trimWhitespace

Constructor Detail

DOMCategoryback to summary
public DOMCategory()

Method Detail

addResultback to summary
private static void addResult(List<E> results, Object result)
Annotations
@SuppressWarnings:unchecked
appendNodeback to summary
public static Element appendNode(Element self, Object name)
appendNodeback to summary
public static Element appendNode(Element self, Object name, Map<K, V> attributes)
appendNodeback to summary
public static Element appendNode(Element self, Object name, String value)
appendNodeback to summary
public static Element appendNode(Element self, Object name, Map<K, V> attributes, String value)
appendNodesback to summary
private static void appendNodes(Node self, Closure<V> c)
attributesback to summary
public static NamedNodeMap attributes(Element element)
breadthFirstback to summary
public static NodeList breadthFirst(Element self)
childrenback to summary
public static NodeList children(Element self)
createNodeListback to summary
private static NodeList createNodeList(Element self)
depthFirstback to summary
public static NodeList depthFirst(Element self)
getback to summary
public static Object get(Element element, String elementName)
getback to summary
public static Object get(NodeList nodeList, String elementName)
getback to summary
public static Object get(NamedNodeMap nodeMap, String elementName)
getAtback to summary
public static Node getAt(Node o, int i)
getAtback to summary
public static Node getAt(DOMCategory.NodeListsHolder o, int i)
getAtback to summary
public static Node getAt(DOMCategory.NodesHolder o, int i)
getAtback to summary
public static NodeList getAt(Node o, IntRange r)
getAtback to summary
public static NodeList getAt(DOMCategory.NodeListsHolder o, IntRange r)
getAtback to summary
public static NodeList getAt(DOMCategory.NodesHolder o, IntRange r)
getChildElementsback to summary
private static NodeList getChildElements(Element self, String elementName)
getNextLevelback to summary
private static NodeList getNextLevel(NodeList thisLevel)
hasChildElementsback to summary
private static boolean hasChildElements(Element self, String elementName)
isEmptyback to summary
public static boolean isEmpty(NodeList self)
isGlobalKeepIgnorableWhitespaceback to summary
public static synchronized boolean isGlobalKeepIgnorableWhitespace()
Returns:boolean

true if ignorable whitespace (e.g. whitespace between elements) is kept; default false

isGlobalTrimWhitespaceback to summary
public static synchronized boolean isGlobalTrimWhitespace()
Returns:boolean

true if text elements are trimmed before returning; default false

listback to summary
public static List<Node> list(NodeList self)
localTextback to summary
public static List<String> localText(Element self)

Returns the list of any direct String nodes of this node.

Returns:List<String>

the list of String values from this node

Since
2.3.0
nameback to summary
public static String name(Node node)
nodeGetAtback to summary
private static Node nodeGetAt(Object o, int i)
nodesGetAtback to summary
private static NodeList nodesGetAt(Object o, IntRange r)
parentback to summary
public static Node parent(Node node)
plusback to summary
public static void plus(Element self, Closure<V> c)
plusback to summary
public static void plus(NodeList self, Closure<V> c)
putAtback to summary
public static void putAt(Element self, String property, Object value)
replaceNodeback to summary
public static Node replaceNode(DOMCategory.NodesHolder self, Closure<V> c)
replaceNodeback to summary
public static Node replaceNode(Node self, Closure<V> c)
setGlobalKeepIgnorableWhitespaceback to summary
public static synchronized void setGlobalKeepIgnorableWhitespace(boolean keepIgnorableWhitespace)

Whether ignorable whitespace (e.g. whitespace between elements) is kept (default false).

Warning

this is a global setting. Altering it will affect all DOMCategory usage within the current Java process.

Parameters
keepIgnorableWhitespace:boolean

the new value

setGlobalTrimWhitespaceback to summary
public static synchronized void setGlobalTrimWhitespace(boolean trimWhitespace)

Whether text content is trimmed (removing leading and trailing whitespace); default false.

Warning

this is a global setting. Altering it will affect all DOMCategory usage within the current Java process. It is not recommended that this is altered; instead call the trim() method on the returned text, but the flag is available to support legacy Groovy behavior.

Parameters
trimWhitespace:boolean

the new value

setValueback to summary
public static void setValue(Element self, String value)
sizeback to summary
public static int size(NamedNodeMap namedNodeMap)
sizeback to summary
public static int size(NodeList self)
textback to summary
public static String text(Node node)
textback to summary
public static String text(NodeList nodeList)
toStringback to summary
public static String toString(Object o)
toStringback to summary
private static String toString(NodeList self)
xgetAtback to summary
private static Object xgetAt(Element element, String elementName)
xgetAtback to summary
private static Object xgetAt(NodeList nodeList, String elementName)
xgetAtback to summary
private static String xgetAt(NamedNodeMap namedNodeMap, String elementName)
xgetAtback to summary
private static Node xgetAt(Element element, int i)
xgetAtback to summary
private static Node xgetAt(NodeList nodeList, int i)
xgetAtback to summary
private static NodeList xgetAt(Element element, IntRange r)
xgetAtback to summary
private static NodeList xgetAt(NodeList nodeList, IntRange r)
xpathback to summary
public static Object xpath(Node self, String expression, QName returnType)
xpathback to summary
public static String xpath(Node self, String expression)
groovy.xml.dom back to summary

private final Class DOMCategory.NodeListsHolder

extends Object
implements NodeList
Class Inheritance
All Implemented Interfaces
org.w3c.dom.NodeList

Field Summary

Modifier and TypeField and Description
private final List<NodeList>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
getLength()

Implements org.w3c.dom.NodeList.getLength.

The number of nodes in the list.
public Node
item(int
Index into the collection.
index
)

Implements org.w3c.dom.NodeList.item.

Returns the indexth item in the collection.
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

nodeListsback to summary
private final List<NodeList> nodeLists

Constructor Detail

NodeListsHolderback to summary
private NodeListsHolder(List<NodeList> nodeLists)

Method Detail

getLengthback to summary
public int getLength()

Implements org.w3c.dom.NodeList.getLength.

Doc from org.w3c.dom.NodeList.getLength.

The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.

itemback to summary
public Node item(int index)

Implements org.w3c.dom.NodeList.item.

Doc from org.w3c.dom.NodeList.item.

Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.

Parameters
index:int

Index into the collection.

Returns:Node

The node at the indexth position in the NodeList, or null if that is not a valid index.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

groovy.xml.dom back to summary

private final Class DOMCategory.NodesHolder

extends Object
implements NodeList
Class Inheritance
All Implemented Interfaces
org.w3c.dom.NodeList

Field Summary

Modifier and TypeField and Description
private final List<Node>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
getLength()

Implements org.w3c.dom.NodeList.getLength.

The number of nodes in the list.
public Node
item(int
Index into the collection.
index
)

Implements org.w3c.dom.NodeList.item.

Returns the indexth item in the collection.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nodesback to summary
private final List<Node> nodes

Constructor Detail

NodesHolderback to summary
private NodesHolder(List<Node> nodes)

Method Detail

getLengthback to summary
public int getLength()

Implements org.w3c.dom.NodeList.getLength.

Doc from org.w3c.dom.NodeList.getLength.

The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.

itemback to summary
public Node item(int index)

Implements org.w3c.dom.NodeList.item.

Doc from org.w3c.dom.NodeList.item.

Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.

Parameters
index:int

Index into the collection.

Returns:Node

The node at the indexth position in the NodeList, or null if that is not a valid index.