Creating an XML document using Java -


i have seen many programs xml documents can created using java specified fields. yet come across 1 user gets decide names of rootelement's , childeelement's. know how go this?

use xstream

java code

xstream xstream = new xstream(); xstream.alias("person", person.class); xstream.alias("phonenumber", phonenumber.class);  person joe = new person("joe", "walnes"); joe.setphone(new phonenumber(123, "1234-456")); joe.setfax(new phonenumber(123, "9999-999"));  string xml = xstream.toxml(joe); 

output xml

<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> 

library: http://x-stream.github.io/tutorial.html


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -