All pastes #33867 Raw Edit

Mine

public text v1 · immutable
#33867 ·published 2005-12-16 09:53 UTC
rendered paste body
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class DomMain { 
	public static void main(String arg[]) {
		try {
			DOMParser parser=new DOMParser();
			
			parser.setIncludeIgnorableWhitespace(true);
			
			parser.setFeature("http://xml.org/sax/features/validation",true);
			parser.parse("document.xml");
			Document doc=parser.getDocument();
			
			//findWithGetElementByTagName(doc);
			findWithByBrowsing(doc);
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}


	public static void findWithGetElementByTagName(Document doc) {
		NodeList nl=doc.getElementsByTagName("acteur");
		
		Node n;
		NodeList nl2;
		for (int i=0;i<nl.getLength();i++) {
			n=nl.item(i); // Get acteur node
			
			nl2=(n.getChildNodes()); // Get acteur children
			for (int j=0;j<nl2.getLength();j++) {
				if (nl2.item(j).getNodeName().compareTo("nom")==0) // Found "nom" child
	              System.out.println(nl2.item(j).getChildNodes().item(0).getNodeValue()); // Get "nom" text
			}
		}
	}
	
	public static void findWithByBrowsing(Document doc) {
		NodeList nl=doc.getChildNodes();
		Node location=nl.item(0);
		NodeList dvdNodes=location.getChildNodes();
		Node film, acteur, nom;
		NodeList filmNodes, acteurNodes, nomNodes; 
		
		for (int dvds=0;dvds<dvdNodes.getLength();dvds++) {
			
			
		}
	}
}