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
|
public static void afficherInfos(Node noeud, int niv) {
ArrayList liste2 = new ArrayList();
short type = noeud.getNodeType();
String nom = noeud.getNodeName();
String valeur = noeud.getNodeValue();
indenter(niv, type == Node.TEXT_NODE);
System.out.print(nom + " (" + type + ") = '");
if(valeur != null && !valeur.matches("^\\s+$"))
System.out.print(valeur);
System.out.println("'");
if ((type == Node.DOCUMENT_NODE || type == Node.ELEMENT_NODE) && noeud.hasChildNodes())
{
if(noeud.hasAttributes())
{
String nom2 = noeud.getNodeName();
NamedNodeMap attributs = noeud.getAttributes();
for(int i = 0; i < attributs.getLength(); i++)
{
Node attribut = attributs.item(i);
Node h = attributs.getNamedItem("title");
String s = h.getNodeValue();
liste2.add(i, s);
afficherInfos(attribut, niv + 2);
}
}
NodeList liste = noeud.getChildNodes();
for (int i = 0; i < liste.getLength(); i++)
afficherInfos(liste.item(i), niv + 1);
}
} |
Partager