简体   繁体   中英

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:

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 eg [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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM