그렇다 :에) (주 될 것이다
final XStream xstream = new XStream(new StaxDriver());
xstream.alias("MyCustomNote", Note.class);
xstream.aliasField("toAddress", Note.class,"to");
xstream.aliasField("fromName", Note.class,"from");
xstream.aliasField("heading", Note.class,"heading");
xstream.aliasField("output", Note.class,"body");
Note.java getMethods()에 @Field를 설정해야합니다. 또한 Note.java을 게시 할 좋은 것 너무
UPDATE :
ExportToXml.class
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
import com.thoughtworks.xstream.io.xml.StaxDriver;
public class ExportToXml {
public Note createNote() {
Note container = new Note();
container.setBody("Don't forget me this weekend!");
container.setFrom("Jeni");
container.setHeading("Reminder");
container.setTo("Tony");
return container;
}
public static void main(String[] args){
final XStream xstream = new XStream(new StaxDriver());
xstream.alias("MyCustomNote", Note.class);
xstream.aliasField("toAddress", Note.class,"to");
xstream.aliasField("fromName", Note.class,"from");
xstream.aliasField("heading", Note.class,"heading");
xstream.aliasField("output", Note.class,"body");
ExportToXml export = new ExportToXml();
Note firstNote = export.createNote();
final File file = new File("D:\\export.xml");
BufferedOutputStream stdout;
try {
stdout = new BufferedOutputStream(new FileOutputStream(file));
} catch (final FileNotFoundException e) {
throw new RuntimeException(e);
}
xstream.marshal(firstNote, new PrettyPrintWriter(
new OutputStreamWriter(stdout)));
}
}
public class Note {
private String to;
private String from;
private String heading;
private String body;
public String getTo() {
return to;
}
public void setTo(String to) {
this.to = to;
}
public String getFrom() {
return from;
}
public void setFrom(String from) {
this.from = from;
}
public String getHeading() {
return heading;
}
public void setHeading(String heading) {
this.heading = heading;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
을 Note.class 결과가 수출 될 것이다. .XML
<MyCustomNote>
<toAddress>Tony</toAddress>
<fromName>Jeni</fromName>
<heading>Reminder</heading>
<output>Don't forget me this weekend!</output>
</MyCustomNote>
다음은 도움이 될 수 http://blog.bdoughan.com/2011/09/mapping-objects-to-multiple-xml-schemas.html –