Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.ProcessingInstruction; public class Main { public static List<ProcessingInstruction> findAllProcessingIstructions(Node node, String name) { List<ProcessingInstruction> result = new ArrayList<ProcessingInstruction>(); findAllProcessingIstructions(node, name, result); return result; } private static void findAllProcessingIstructions(Node node, String name, List<ProcessingInstruction> result) { 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)) { result.add((ProcessingInstruction) n); } } findAllProcessingIstructions(n, name, result); } } }