Java – save data in an XML file
•
Java
I have an application. I need to save data input as a user in an XML file at a specified location. I need to use java to execute it I have relatively new XML processing in Java I'd like to make some suggestions on how to start the task
Any snippets and links will help
thank you
Solution
There is a very good framework JAXB for this, and there is also simple
But I have used this xStream
Person joe = new Person("Joe","Walnes");
joe.setPhone(new PhoneNumber(123,"1234-456"));
joe.setFax(new PhoneNumber(123,"9999-999"));
Now, to convert it to XML, you simply call xStream:
String xml = xstream.toXML(joe);
The generated XML is as follows:
<person>
<firstname>Joe</firstname>
<lastname>Walnes</lastname>
<phone>
<code>123</code>
<number>1234-456</number>
</phone>
<fax>
<code>123</code>
<number>9999-999</number>
</fax>
</person>
See also
> JAXB > where-i-can-find-a-detailed-comparison-of-java-xml-frameworks
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
