I have a client program which sends the XML data to my server program.
The server needs to parse the XML data.
I am using C language with Linux.
Is there any API available to parse XML from sockets directly?
otherwise how could I know whether the XML transfer is completed or not?
As I tried to explain above: when you use “raw sockets”, you’ll read at most a buffer at a time. You won’t necessarily read the whole document in one socket read; you might not even get a complete line. You need to copy the data a buffer at a time, in a loop, until you get all the text you need. This complicates parsing 🙂
Expat is a stream-oriented parser – that will probably help.
SAX is an “event driven” parser. You can use a SAX wrapper around Expat, you can also use any of many other choices, including libXML and Xerces.
The main point is that 1) reading your data (from the network), and 2) parsing your data are two separate activities.
For learning sockets, I’d strongly recommend Beej’s Most Excellent “Network Programming Guide”:
For learning Expat, here’s a good tutorial:
‘Hope that helps..