I have an XML file with this structure:
<?xml version="1.0">
<person>
<element att1="value1" att2="value2">Anonymous</element>
</person>
How can I extract the attributes names and values using wathever you want.
I tried JDOM, but I still can't find a way to get the attributes from the element.
Element root = doc.getRootElement();
List allChildren = root.getChildren();
Iterator i = listEtudiants.iterator();
while(i.hasNext())
{
Element current = (Element)i.next();
System.out.println(current.getChild("elementName").getText());
// this let me get just the value inside > anf </
// so, if it's can be done by completing this code
// it will be something like current.getSomething()
}
EDIT: I'm still having a problem with this file. I can't reach foo attribute and its value moo.
<?xml version="1.0" encoding="UTF-8"?>
<person>
<student att1="v1" att2="v2">
<name>Michel</name>
<prenames>
<prename>smith</prename>
<prename>jack</prename>
</prenames>
</student>
<student classe="P1">
<name foo="moo">superstar</name>
</student>
</person>