Java7
Posts tagged xml
Spring Empty Bean Definition XML
Dec 23rd
For Spring 2.5:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
</beans>
Another 2.5 Spring bean definition descriptor:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
</beans>
For Spring 3:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
</beans>
Source: http://static.springsource.org/spring/docs/2.5.x/reference/beans.html
Starting JSON, a practical approach. Part 1
Nov 20th
Introduction
Most of us are familiar with basic XML data format because it is greatly understood and is itself a key enabler of many technologies and concepts, the most prominent – web services.
However, XML itself when used in transportation of data over HTTP protocol carries a substantial amount of by product i.e. the descriptive markup tags itself. JavaScript Object Notation (JSON) in comparison is lightweight, lean, and can be as easily understood by the human eye as its XML counterpart when viewed with a JSON formatting phaser.
Just recently, my colleague was tasked with the challenge of minimizing the HTTP content and exchange of a particular use case which has heavy XML. His proposal – gun zipping the XML. I would be curious if he would be able to do a comparison for his solution, and a solution using JSON.
1. Simple object with one domain data
Lets see we have a Zoo called ‘Cityhall State Zoo’ that we need to represent in markup.
XML
<Zoo>Cityhall State Zoo</Zoo>
JSON
{"Zoo": "Cityhall State Zoo"}
2. Simple object with more than one domain data
Our Zoo has now a need to accommodate a Lion.
XML
<Zoo>
<Name>Cityhall State Zoo</Name>
<Animal>Lion</Animal>
</Zoo>
JSON
{"Zoo": {"name": "Cityhall State Zoo", "animal": "Lion"}}
3. Simple object with an array of domain data
We are having more animals in the Zoo than when we had when we first started off!
XML
<Zoo>
<name>Cityhall State Zoo</name>
<Animals>
<Animal>Lion</Animal>
<Animal>Tiger</Animal>
<Animal>Elephant</Elephant>
</Animals>
</Zoo>
JSON
{"Zoo": {"name": "Cityhall State Zoo", "animals": ["Lion", "Tiger", "Elephant"]}}
4. An array of domain objects
So far above we have been having only domain data in our array, for example, String data or Integer data. You may contain domain objects in your array.
XML
<Zoo>
<name>Cityhall State Zoo</name>
<Animals>
<Animal>
<name>Lion</name>
<weight>3.45kg</weight>
<kingdom>Animalia</kingdom>
</Animal>
<Animal>
<name>Tiger</name>
<weight>5kg</weight>
<kingdom>Animalia</kingdom>
</Animal>
</Animals>
</Zoo>
JSON
{"Zoo":{"name":"Cityhall State Zoo", "Animals":[{"Animal":{"name":"Lion", "weight":"3.45kg", "kingdom":"Animalia"}},{"Animal":{"name":"Tiger", "weight":"5kg", "kingdom":"Animalia"}}]}}
Interesting Reads
Look at this stackoverflow question regarding a malformed JSON string, some parser are more tolerant, while some are stricter. So watch out!
Revision
March 21, 2011 Improved XML readability with tab formatting. Edited introductory text.
July 7, 2011 Added a link to a stackoverflow question on JSON string parsing.