Re: [xml] how to read and parse an xml from socket?

Thanks, Eric :)

Good to know this so that I do not spend more time on the socket approach. Yes, I am switching to the xmlParseMemory approach.


Eric S. Eberhard wrote:

I have never had good luck with parsing off a socket. I find it much easier to just read off the socket myself in to a memory area, and then parse the memory area using xmlParseMemory

Of course, if you read off the socket yourself make sure and look for the end tag to speed things up. And, of course, don't read past the end tag ...


At 04:56 PM 1/22/2007, Steve Yan wrote:
Thanks a lot, Daniel.

For windows, HANDLE (and SOCKET) are defined as void *. Since the
libxml2 takes fd (integer type) as its argument, I am using the
following function to get fd from HANDLE:

int fd = _open_osfhandle((long)my_handle, O_RDONLY);

However, when I call libxml2 function such as:

    xmlTextReaderPtr  reader = xmlReaderForFd(fd, NULL, NULL,

    if (reader != NULL) {
        ret = xmlTextReaderRead(reader);

xmlTextReaderRead(reader) returns -1, and I got the following error;

I/O Error: Invalid argument
Entity:  line 1: parser error: Extra content at the end of document.

BTW, the XML string is valid and no extra  content at its end.

What is the problem? What to do to read xml from socket in windows?


Daniel Veillard wrote:
> On Sat, Jan 20, 2007 at 05:57:27PM -0800, Steve Yan wrote:
>> Hi,
>> This may be a question asked by people before, but I could not find answer
>> from google.
>   Bad excuse:
>> I am trying to read out and parse XML from a socket, which API should I
>> use? any sample code?
> There is multiple parsing APIs, tree, xmlReader or SAX, all of them can > consume from a file descriptor, and you can build your own I/O handlers too.
> and
> Daniel
> P.S.: posting a completely unrelated message by replying to an existing
>       mail and changing the subject if fine if you understand you also
> need to remove the In-Reply-To: and References: headers, otherwise > you just break mail threading of people using decent email clients...
>       Please don't do that !
xml mailing list, project page
xml gnome org

This email sent by:

Eric S. Eberhard
(928) 567-3727          Voice
(928) 567-6122          Fax
(928) 301-7537                           Cell

For Metropolis support and VICS MBA Support!!!!

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]