Open JonathanGiles opened 4 years ago
Auto-imported comment, original author: jpeacock Comment posted on: September 12, 2008
Doesn't XStream already do this easily?
Auto-imported comment, original author: Jonathan Comment posted on: September 12, 2008
Yes, it does, but as I noted, it is a simple implementation for a specific circumstance, and in that instance having to use something more complex is overkill. XStream binary packages are nearly 8mb, which is overkill for when the only need is to quickly and easily interpret a string of xml, as was my use case.
Auto-imported comment, original author: Hema Comment posted on: September 12, 2008
There are already lot of Java Data Binding framework available like CASTOR, XSTREAM, JAXB... why can't you use one of them?
Auto-imported comment, original author: Baptiste Comment posted on: September 12, 2008
Yes XStream is extremely big.
There is Simple: http://simple.sourceforge.net/
Simple 184kB Dependencies: Stax 176kB Stax-Api 28kB
Auto-imported comment, original author: Ben Comment posted on: September 12, 2008
JAX-B either schemagen to make a schema out of models and then its a one line thing to unmarshel into models is a lot easier imo method. Plus the latest version comes shipped in the current JDK.
Auto-imported comment, original author: James Comment posted on: September 13, 2008
We use dom4j to unmarshall xml. I like its api for pulling out specific xml elements/attributes. It's 307KB and you have to use XPath queries, which can be a pain, but it's darn good.
Auto-imported comment, original author: kevinw Comment posted on: September 13, 2008
what about or <![CDATA[ This is valid xml even containing ]]>
Auto-imported comment, original author: Jonathan Comment posted on: September 13, 2008
James, thanks for the comment about dom4j. I'm always loath to include new libraries (especially given the number of xml libraries!), but I'm always happy to hear recommendations. I too have used xpath queries to pull out specific values, and that is a good approach for a more complex xml structure, but I still like the above code for simple use cases.
Kevin, unfortunately it looks like wordpress removed some of your xml syntax there, so I can't give a proper answer. Regardless, my use case is a very simple one, and the implementation above is only enough to meet that use case. I have not tested it on more difficult scenarios, although I'm sure the code could be improved to handle them.
Basic XML Unmarshalling in Java
https://jonathangiles.net/posts/2008/basic-xml-marshalling-in-java/