You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by bu...@apache.org on 2002/03/07 23:58:23 UTC
DO NOT REPLY [Bug 6969] New: -
parse of in-memory stream can't handle adjacent elements with no white space between them
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6969>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=6969
parse of in-memory stream can't handle adjacent elements with no white space between them
Summary: parse of in-memory stream can't handle adjacent elements
with no white space between them
Product: Xerces-C++
Version: 1.6.0
Platform: PC
OS/Version: Windows NT/2K
Status: NEW
Severity: Blocker
Priority: Other
Component: Non-Validating Parser
AssignedTo: xerces-c-dev@xml.apache.org
ReportedBy: tdodd@iss.net
There are actually two problems:
1. If I have an XML document like this
<?xml version='1.0' encoding='UTF-8' standalone='no'?><fred/>
an in-memory non-validating parse using MemBufInputSource chokes on it, giving
the error:
line 1, column 56: Expected an element name.
But if I insert a space or newline after the XML declaration, like this
<?xml version='1.0' encoding='UTF-8' standalone='no'?> <fred/>
the document parses without any difficulty.
2. In the 2nd case above, in which the document parses okay, the resultant
document yields a null root element. However, if I take that exact same text
and put it in a file and parse the file, I get a good root element. Either
version of the text above, if parsed from a file, yields a good root element.
Here's some sample code that demonstrates the problem:
---
#include "stdafx.h"
#include "MyException.h"
#include "MyErrorHandler.h"
// Application-wide ininitialization and termination of Xerces XML parser.
namespace
{
struct XmlInit
{
XmlInit() { XMLPlatformUtils::Initialize(); }
~XmlInit() { XMLPlatformUtils::Terminate(); }
} xmlInit;
CMySaxErrorHandler ErrHandler;
}
void GetDOMStringData(const DOMString& domString, std::wstring& wstrData)
{
wstrData.erase();
unsigned int nStrlen = domString.length();
for (unsigned int i = 0; i < nStrlen; ++i)
{
wstrData += domString.charAt(i);
}
}
LPCWSTR wszTestContentGood =
L"<?xml version='1.0' encoding='UTF-8' standalone='no'?> <fred/>";
LPCWSTR wszTestContentBad =
L"<?xml version='1.0' encoding='UTF-8' standalone='no'?><fred/>";
int wmain(int argc, wchar_t* argv[])
{
int nResult = 0;
try
{
DOMParser parser;
// Configure parser for a validating parse.
parser.setErrorHandler(&ErrHandler);
parser.setDoSchema(false);
parser.setValidationScheme(DOMParser::Val_Never);
std::wcout << L"Parsing in-memory version of 'Good Test Stream'..." <<
std::endl;
parser.parse(MemBufInputSource(reinterpret_cast<const XMLByte*>
(wszTestContentGood),
wcslen(wszTestContentGood) * sizeof(wchar_t), L"Good Test Stream"));
DOM_Document document = parser.getDocument();
DOM_Element root = document.getDocumentElement();
if (root.isNull())
{
std::wcout << L"In-memory 'Good Test Stream' yields null root
element" << std::endl;
}
else
{
std::wstring wstrTagname;
GetDOMStringData(root.getNodeName(), wstrTagname);
std::wcout << L"In-memory 'Good Test Stream yields good root
element '" << wstrTagname << L"'" << std::endl;
}
parser.reset();
std::wcout << L"Parsing file version of 'Good Test Stream'..." <<
std::endl;
// GoodContent.xml contains the same text as the in-memory version
of 'Good Test Stream.'
parser.parse(LocalFileInputSource(L"GoodContent.xml"));
document = parser.getDocument();
root = document.getDocumentElement();
if (root.isNull())
{
std::wcout << L"File version of 'Good Test Stream' yields null root
element";
}
else
{
std::wstring wstrTagname;
GetDOMStringData(root.getNodeName(), wstrTagname);
std::wcout << L"File version of 'Good Test Stream yields good root
element '" << wstrTagname << L"'" << std::endl;
}
parser.reset();
std::wcout << L"Parsing in-memory variant: 'Bad Test Stream'..." <<
std::endl;
parser.parse(MemBufInputSource(reinterpret_cast<const XMLByte*>
(wszTestContentBad),
wcslen(wszTestContentBad) * sizeof(wchar_t), L"Bad Test Stream"));
}
catch (const CMyException& e)
{
std::wcout << e << std::endl;
nResult = e.GetCode();
}
return nResult;
}
---
When I run this program (after , I get:
---
Parsing in-memory version of 'Good Test Stream'...
In-memory 'Good Test Stream' yields null root element
Parsing file version of 'Good Test Stream'...
File version of 'Good Test Stream yields good root element 'fred'
Parsing in-memory variant: 'Bad Test Stream'...
Parse operation: Fatal error parsing file "Bad Test Stream", line 1, column 56
Message: Expected an element name; error = 0x3
---
If this is not enough information, please let me know. Unfortunately, this web
page doesn't have a means of attaching files. I'll let you have the rest of my
source code (error handler & exception object) if you wish.
thanks,
tim
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org