You could use JAXB (JSR-222) to read the XML into Java objects that you could process as you wish. An implementation of JAXB is included in the JDK/JRE starting with Java SE 6. Below is an example:
Config
JAXB is configuration by exception. This means you only need to add annotations where you want the XML representation to differ from the default (see: http://blog.bdoughan.com/2012/07/jaxb-no-annotations-required.html).
package forum12448687;
import java.util.List;
import javax.xml.bind.annotation.*;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Config {
private List<Art> art;
}
Art
package forum12448687;
import java.util.List;
import javax.xml.bind.annotation.*;
@XmlAccessorType(XmlAccessType.FIELD)
public class Art {
private String name;
private String first;
@XmlElementWrapper
@XmlElement(name="set")
private List<String> alist;
}
Demo
The code below demonstrates how to read the XML into object from and then write it back to XML.
package forum12448687;
import java.io.File;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Config.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("src/forum12448687/input.xml");
Config config = (Config) unmarshaller.unmarshal(xml);
Marshaller marshaller= jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(config, System.out);
}
}
input.xml/Output
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config>
<art>
<name>x</name>
<first>y</first>
<alist>
<set>1</set>
<set>2</set>
<set>3</set>
</alist>
</art>
<art>
<name>z</name>
<first>a</first>
<alist>
<set>1</set>
<set>2</set>
<set>3</set>
</alist>
</art>
</config>