[Expat-discuss] Expat 1.95.8 fails on XML with newline

Jeff Lambert jeffl at hypershell.com
Tue Nov 23 14:46:27 CET 2004


I saw something similar on the sourceforge bugs list but it was from 
2001 so I assume it's fixed by now.

O/S: WinXP SP2 and WinCE. Expat lib linked in VC++ 6 SP6.

I have the following XML (simplified for discussion purposes) The XML 
starts and ends with the braces.

{

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
  </soapenv:Body>
</soapenv:Envelope>}

NOTICE the newline(0A) at the beginning of the file. Now I use the 
following C++ code to read from the XML file:

do
{
   size_t len = fread(buf, 1, sizeof(buf), xmlfile);
   done = len < sizeof(buf);
   if (XML_Parse(parser, buf, len, done) == XML_STATUS_ERROR)
   {
     return ReturnLua(State, 1, "Error while parsing.");
   }
} while (!done);

This works mint on all other XML files, but not with that one. This is 
how the XML file is returned to me by a SOAP server. What happens is 
that on first pass through the while loop, XML_Parse doesn't even go 
into the functions previously set, it instantly returns 
XML_STATUS_ERROR, and the rest is history.

I would like to know if the error is in my file reading code or an Expat 
bug. If it is the latter, is there a patch or quick fix? And if it is my 
  code, then what could I do to strip the initial newline(s)?

Thanks in advance!

Jeff Lambert


More information about the Expat-discuss mailing list