我想将字符串转换为xml,然后使用createUnmarshaller方法转换为pojo实体。
的xmlString:
<File>
<code>63213713</code>
<name>textsss</name>
<player>GAMMER</player>
<system>SS</system>
<File>
My Method将String转换为Xml:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Source src = null;
DocumentBuilder builder;
try {
builder = factory.newDocumentBuilder();
// Use String reader
Document document = builder.parse( new InputSource(new StringReader( xmlString ) ) );
src = new DOMSource( document );
FileWriter writer = new FileWriter(new File("./src/main/folder/xmlFile.xml"));
StreamResult result = new StreamResult(writer);
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.transform(src, result);
我有方法Marshaller:
JAXBContext context = JAXBContext.newInstance("br.com.Test.domain");
Marshaller m = context.createMarshaller();
Unmarshaller um = context.createUnmarshaller();
Object obj = um.unmarshal();
如何将String转换为xml并使用此方法Marshaller?我不明白如何为方法unmarshaller传递方法转换的结果。 我应该通过什么样的方式?来源?