XML Databinding really simple
XStream is the kind of project which is so easy and so great, that if somebody try give a presenation about that could be hard spend more than five minutes.
I've used XStream on some new supports for Greebox in order to allow Eclipse Developers use it.
Here I will take a piece of tests of my evaluations:
xml = new XStream();
xml.alias("class",net.java.dev.greenbox.base.Clazz.class);
xml.alias("attribute",net.java.dev.greenbox.base.Attribute.class);
xml.aliasField("package",net.java.dev.greenbox.base.Clazz.class,"packageName");
xml.aliasField("name",net.java.dev.greenbox.base.Clazz.class,"className");
classe = new Clazz();
classe.setPackageName("br.com.summatech.greenboxsamplexml.contact");
classe.setClassName("Contact");
Attribute nameContact = new Attribute();
nameContact.setName("name");
nameContact.setDataType("String");
nameContact.setAcessor("private");
Attribute email = new Attribute();
email.setName("email");
email.setDataType("String");
email.setAcessor("private");
ArrayList attrs = new ArrayList();
attrs.add(nameContact);
attrs.add(email);
classe.setAttributes(attrs);
System.out.println(xml.toXML(classe));
And the Result:
<class>
<package>br.com.summatech.greenboxsamplexml.contact</package>
<name>Contact</name>
<attributes>
<attribute>
<acessor>private</acessor>
<dataType>String</dataType>
<name>name</name>
</attribute>
<attribute>
<acessor>private</acessor>
<dataType>String</dataType>
<name>email</name>
</attribute>
</attributes>
</class>
So now, I can marshall and unmarchall object really easy! thanks codehaus :D and XStream team. Solutions like that could be part of JSE.
- Login or register to post comments
- Printer-friendly version
- edgars's blog
- 454 reads





