Java Utililty Methods XML NodeList

List of utility methods to do XML NodeList

Description

The list of methods to do XML NodeList are organized into topic(s).

Method

Node[]convertToArray(NodeList list)
convert To Array
int length = list.getLength();
Node[] copy = new Node[length];
for (int n = 0; n < length; ++n)
    copy[n] = list.item(n);
return copy;
ListconvertToElementList(org.w3c.dom.NodeList _nodeList)
Convert a NodeList to a Java List of Element s.
List<org.w3c.dom.Element> elemList = new ArrayList<>();
for (int i = 0; i < _nodeList.getLength(); i++) {
    Element elem = (org.w3c.dom.Element) _nodeList.item(i);
    elemList.add(elem);
return elemList;
ListcopyNodeList(NodeList nodeList)
Copy a given NodeList into a List
ArrayList<Node> copy = new ArrayList<Node>();
int length = nodeList.getLength();
for (int i = 0; i < length; i++) {
    copy.add((Node) nodeList.item(i));
return copy;
CollectioncreateNodeCollection(final NodeList nodeList)
create Node Collection
return new Collection<Node>() {
    @Override
    public int size() {
        return nodeList.getLength();
    @Override
    public boolean isEmpty() {
        return nodeList.getLength() > 0;
...
ListcreateRealNodeList(NodeList nodeList)
create Real Node List
List<Node> realNodeList = new LinkedList<Node>();
if (null != nodeList && nodeList.getLength() > 0) {
    for (int i = 0; i < nodeList.getLength(); ++i) {
        Node nextNode = nodeList.item(i);
        realNodeList.add(nextNode);
return realNodeList;
...
booleanequalNodes(NodeList sourceNodeList, NodeList targetNodeList)
equal Nodes
ArrayList sourceNodes = new ArrayList();
ArrayList targetNodes = new ArrayList();
getAllNodes(sourceNodeList, sourceNodes);
getAllNodes(targetNodeList, targetNodes);
int sourceLength = sourceNodes.size();
int targetLength = targetNodes.size();
if (sourceLength != targetLength) {
    return false;
...
ListextractElementsFromNodeList(NodeList config, String tag, boolean required)
extract Elements From Node List
List<Element> res = new ArrayList<Element>();
for (int i = 0; i < config.getLength(); i++) {
    Node n = config.item(i);
    if (n.getNodeType() == Node.ELEMENT_NODE && n.getNodeName().equals(tag)) {
        res.add((Element) config.item(i));
if (required && res.size() == 0) {
...
NodeListextractNodeListFromElement(Element config, String tag, boolean required)
extract Node List From Element
NodeList node = config.getElementsByTagName(tag);
return check1Most(node, tag, required);
voidfillHashtable(NodeList list, Hashtable fillIn)
fill Hashtable
for (int curElemNum = 0; curElemNum < list.getLength(); curElemNum++) {
    if (list.item(curElemNum).getNodeType() != Node.ELEMENT_NODE)
        continue;
    Element curValue = (Element) list.item(curElemNum);
    String valueName = curValue.getNodeName();
    String value = curValue.getFirstChild().getNodeValue();
    fillIn.put(valueName, value);
voidfillHashtable(NodeList list, Hashtable fillIn)
fill Hashtable
for (int curElemNum = 0; curElemNum < list.getLength(); curElemNum++) {
    if (list.item(curElemNum).getNodeType() != Node.ELEMENT_NODE)
        continue;
    Element curValue = (Element) list.item(curElemNum);
    String valueName = curValue.getNodeName();
    String value = curValue.getFirstChild().getNodeValue();
    fillIn.put(valueName, value);