I tried the solutions given online but none of them work. Tools used : Hibernate Maven Eclipse IDE JAXB JSP HTML

I have several bean classes. I have mapped them to the schema as well using hbm xmls.. I am looking to convert the objects to xml and store it in an xml file. Please help me out with an example

有帮助吗?

解决方案

I was thinking that rather than loading from the DB on server restart, I could load from the local file!! (as the data in the db updates less often) that's where I got to learn about the XStream Library, and it's so simple that I could convert any java object to XML and back.

Detail

其他提示

without annotations how do you plan to bind data?

XML is a pure structured language. So, if you are marshaling any object, you need to also tell the structure.

So, if you don't want to put annotations you have to let java know the structure using XSD.

Check this example for using XML Schema Definition.

If you are more interested in finding a simpler solution for marshalling you can try XMLEncoder or if you are comfortable with JAXP, you can pick any one implementation.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top