Reputation: 7228
I have a lot of XML files as below. How can I create Java class (Java object) from it automatically? How to update key and value in the String?
`<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="MODE" value="1"/>
<add key="NAME" value="DIRN2"/>
</appSettings>
</configuration>`
public void createPc("pc.xml"){
XStream xstream = new XStream();
Pc newpc = (Pc)xstream.fromXML(pc.xml);
// updating key and value
????????????
}
Upvotes: 1
Views: 1172
Reputation: 1832
Use JaxB. Inorder to create objects, using JaxB, all you need to do is define XSD for your XMLs and generate the classes for your XSD.
Upvotes: 1
Reputation: 803
Creates automatically the classes you need from the xmls.
You need to marshall and unmarshall it to populate the java objects and update the xml file.
Upvotes: 0