The list of methods to do XML Node Find are organized into topic(s).
int
findAllDescendantElements(Node e, String qname, Collection vector) find All Descendant Elements
int n = 0;
if (e == null || qname == null)
return 0;
for (Node c = e.getFirstChild(); c != null; c = c.getNextSibling()) {
if (c.getNodeType() == Node.ELEMENT_NODE && c.getNodeName().equals(qname)) {
++n;
vector.add((Element) c);
n += findAllDescendantElements(c, qname, vector);
return n;
void
findAllNodes(Node node, String[] nodeNames, ArrayList results) find All Nodes
NodeList nodes = node.getChildNodes();
if (nodes != null) {
for (int i = 0; i < nodes.getLength(); i++) {
for (int j = 0; j < nodeNames.length; j++) {
if (nodes.item(i).getNodeName().equals(nodeNames[j])) {
results.add(nodes.item(i));
findAllNodes(nodes.item(i), nodeNames, results);
void
findAllProcessingIstructions(Node node, String name, List result) find All Processing Istructions
NodeList nodeList = node.getChildNodes();
if (nodeList == null) {
return;
for (int i = 0; i < nodeList.getLength(); ++i) {
Node n = nodeList.item(i);
if (n.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
if (name == null || name.length() == 0 || n.getNodeName().equals(name)) {
...
void
findAllUrisRecursive(Node node, List nodes) find All Uris Recursive
String url = getSafeAttribute(node, "uri");
if (url != null) {
nodes.add(node);
NodeList children = node.getChildNodes();
if (children != null) {
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
...
Element
findElement(Node node, String tagName) find Element
Element result = null;
NodeList nodeList = node.getChildNodes();
if (nodeList == null) {
return result;
for (int i = 0; i < nodeList.getLength(); ++i) {
Element element = checkIfElement(nodeList.item(i), tagName);
if (element != null) {
...
Element
findElement(Node startNode, String name, String namespace) Returns the first element that matches
name and
namespace.
if (startNode == null) {
return null;
Node startParent = startNode.getParentNode();
Node processedNode = null;
while (startNode != null) {
if (startNode.getNodeType() == Node.ELEMENT_NODE && startNode.getLocalName().equals(name)) {
String ns = startNode.getNamespaceURI();
...
Element
findElementById(Node head, String id) Static method to find DOM elements by an ID field
Element element = null;
for (Node node = head.getFirstChild(); node != null; node = node.getNextSibling()) {
if (node.hasChildNodes()) {
element = findElementById(node, id);
if (element != null)
return element;
if (node.hasAttributes()) {
...
Element
findElementById(Node node, String id) Find descendant element having specified id attribute.
Node child = node.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) child;
String value = childElement.getAttributeNS(null, "id");
if (value != null && value.length() > 0) {
value = value.trim();
if (value.equals(id)) {
...
Element
findElementByName(Node node, final String name) Look for Element node of given name.
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE && node.getNodeName().equals(name))
return (Element) node;
node = node.getNextSibling();
return null;