import java.io.IOException; import java.lang.*; import org.w3c.dom.Attr; import org.w3c.dom.*; import org.apache.xerces.parsers.DOMParser; import org.xml.sax.*; public class DOMParserDemo { public void performDemo(String uri) { DOMParser parser = new DOMParser(); try { parser.parse(uri); Document doc = parser.getDocument(); doc = transform(doc); printNode(doc); } catch (Exception e) {} } public Document transform(Document doc) { /* écrire ici (solution "élégante" uniquement) */ return doc; } public void printNode(Node node) { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: Document doc = (Document) node; System.out.println(""); printNode(doc.getDocumentElement()); break; case Node.ELEMENT_NODE: System.out.print("<"); /* écrire ici */ System.out.print(node.getNodeName()); NamedNodeMap attributs = node.getAttributes(); for (int i=0; i"); NodeList children = node.getChildNodes(); if (children != null) { for (int i=0; i"); break; case Node.TEXT_NODE: System.out.print(node.getNodeValue()); break; } } public static void main(String[] args) { String uri = args[0]; //System.out.println("En train de traiter fichier "+uri); DOMParserDemo parserDemo = new DOMParserDemo(); parserDemo.performDemo(uri); } }