1

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
       ????????????
 }
1
  • Try XStream. Check my answer here Commented Mar 5, 2012 at 10:51

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

You do not require an XML schema to use JAXB (JSR-222). You can start with Java classes and use annotations to control the XML representation: wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted
0

http://www.castor.org/

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.