Search an other solution to retrieve data xml with DOM

hi

i have a xml file , i need to retrieve certain data of xml.

so i process of this way :

publicclass ParserDOMBegeti

{

static Document document;//document

static Element rootElement;//racine

publicstaticvoid main(String[] args)

{

try{

// cr閍tion d'une fabrique de documents

DocumentBuilderFactory fabrique = DocumentBuilderFactory.newInstance();

// cr閍tion d'un constructeur de documents

DocumentBuilder constructeur = fabrique.newDocumentBuilder();

document = constructeur.parse(new File("DAG08360_malencon_10-101-4-197_000802E2BF23.xml"));

// parser pour construire le Dom

rootElement = document.getDocumentElement() ;

// recuperer le premier element du Dom (cad root)

printDomTree (rootElement,"");

}catch (Throwable t)

{

t.printStackTrace ();

System.exit (1);

}

NodeList EnfantNode = document.getElementsByTagName("Page");

for(int i=0 ; i<EnfantNode.getLength(); i++)

{

Element el1 = (Element)EnfantNode.item(i);

NodeList GroupNode = el1.getElementsByTagName("Group");

for(int j=0 ; j><GroupNode.getLength();j++)

{

Element el2 = (Element)GroupNode.item(j);

// System.out.println("-group-"+ el2.getFirstChild().getFirstChild().getNodeValue());

String nameGroup = el2.getFirstChild().getFirstChild().getNodeValue();

// System.out.println("nameGroup" + nameGroup);

if(nameGroup.equals("Ordinateur"))

{

System.out.println("Ordinateur");

NodeList ItemNode = el2.getElementsByTagName("Item");

for(int k=0 ; k><ItemNode.getLength();k++)

{

Node el3 = (Element)ItemNode.item(k);

System.out.println("-valeur-"+ el3.getFirstChild().getNextSibling().getNextSibling().getFirstChild().getNodeValue());

}

}

if(nameGroup.equals("Carte m鑢e"))

{

System.out.println("Carte m鑢e");

NodeList ItemNode = el2.getElementsByTagName("Item");

for(int k=0 ; k><ItemNode.getLength();k++)

{

Node el3 = (Element)ItemNode.item(k);

//System.out.println("-title-"+ el3.getFirstChild().getNextSibling().getNextSibling().getNodeName());

// System.out.println("-icon-"+ el3.getFirstChild().getNextSibling().getNodeName());

System.out.println("-valeur-"+ el3.getFirstChild().getNextSibling().getNextSibling().getFirstChild().getNodeValue());

afficher(1);

}

}

I know it's not the best way to process , have you got an idea how can i to do it ?

i saw on several forum that i can do an reflexive method

so i did that

printDomTree(node, ident)

{

System.out.println("NameNode " + node.getNodeName());

System.out.println("ValueNode " + node.getNodeValue());

if (node.hasChildNodes())

{

// comme les Tree-s JAVA .....

Node nextFils = node.getFirstChild();

while (nextFils !=null)

{

printDomTree (nextFils,indent+" ");

nextFils = nextFils.getNextSibling();

}

}

}

This way allow me to display my data but i can't retrieve my data selected.

I thought to put each data xml on Arraylist but it don't work

Have you got an idea to help me ?

thanks you>

[5398 byte] By [hanimichia] at [2007-11-26 22:56:52]
# 1

hi

well i use an recursive method to display my xml.

So my question is how can i retrieve certain this data?

Is that possible to retrieve to put all this data in array and after i manage the array 've just created ?

I don't know if it's the best way or it works!!

thanks you

hanimichia at 2007-7-10 12:21:52 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...