tags:

views:

85

answers:

2

I'm newbie to XML using Java. I've to write a method to send a large XML data having lots of nodes through a socket to client application. What is the suitable method to generate XML? What is the best method to send large XML through sockets?

+1  A: 

To generate XML you use DOM implementation provided by any XML DOM parser and generator. Here is a nice tutorial. But for only generation try to use some small and light-weight parcers e.g. [tinyxml][2] or [qdparcer][3], because the xerces and others are going to be heavy weight for that. But if the parcing is also involved libxml or xerces will be of good choice because they provide nice SAX implementation for parsing, but you need to have schema defined for your data. Again try to serialize the data before sending so you can get rid of other problems.

yadab
+1  A: 

Since you are using sockets you just need to deal with Java InputStream/OutputStream. This gives you alot of flexibility in your XML handling as almost all XML technologies handle streams as input/output.

You could represent your data as plain old Java objects (POJOs), and then bind them to XML using JAXB. An implementation of JAXB is included in Java SE 6. There are other implementations such as MOXy (I'm the tech lead) and JaxMe.

For an example see:

Blaise Doughan