1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
import java.io.IOException;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class Test{
public static void main(String[] argv){
// Create a DOM Parser
DOMParser parser = new DOMParser();
try{
// Parser the incoming file (URL)
parser.parse("test.xml");
}catch(IOException ioe){
ioe.printStackTrace();
}catch(SAXException se){
se.printStackTrace();
}
// Obtain the document
Document doc = parser.getDocument();
Element root = (Element)doc.getDocumentElement();
NodeList a= root.getElementsByTagName("a");
for(int cpt=0; cpt < a.getLength(); cpt++){
Element node= (Element)a.item(cpt);
System.out.println("valeur node="+node);
}
}
} |