开发者

Sending large xml data through a socket

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?


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:

  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/GettingStarted


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜