The XML we are trying to parse is not sending a SYSTEM ID. Its a 3rd party app and we have no control over this. It looks like we'll need to intercept and modify the DOCTYPE by adding a SYSTEM ID for this to work.
Mark
Mark Horton wrote:
I thought I would post my test code in case someone can spot where I've gone wrong. test1() tries to cache and use a DTD by using loadGrammar(). test2() tries to cache the DTD from a parsed xml file.
void test::test1()
{
XercesDOMParser parser;
testErrorHandler errorHandler;
try
{
parser.setErrorHandler(&errorHandler);
parser.setValidationScheme(XercesDOMParser::Val_Always);
parser.setDoSchema(true);
parser.setDoNamespaces(true);
parser.loadGrammar(dtd, Grammar::DTDGrammarType, true);
parser.useCachedGrammarInParse(true);
parser.parse(xml); // this prints out validation errors
}
catch (...)
{
cerr << "Unexpected exception." << endl;
}
}
void test::test2()
{
XercesDOMParser parser;
testErrorHandler errorHandler;
try
{
parser.setErrorHandler(&errorHandler);
parser.setValidationScheme(XercesDOMParser::Val_Always);
parser.setDoSchema(true);
parser.setDoNamespaces(true);
parser.cacheGrammarFromParse(true);
parser.parse(xml2);
parser.useCachedGrammarInParse(true);
parser.parse(xml); // this prints out validation errors
}
catch (...)
{
cerr << "Unexpected exception." << endl;
}
}
Both methods print out the same errors:
Error at line 3, column 10
Message: Unknown element 'message'
Error at line 4, column 14
Message: Unknown element 'fposition'
Error at line 5, column 12
Message: Unknown element 'flength'
Error at line 6, column 9
Message: Unknown element 'line'
Somehow the DTD is not being used at all. Here are the 3 files:
dtd
===
<?xml version='1.0' encoding='utf-8'?>
<!ELEMENT message (fposition, flength, line)>
<!ELEMENT fposition (#PCDATA)>
<!ELEMENT flength (#PCDATA)>
<!ELEMENT line (#PCDATA)>
xml
===
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE message>
<message>
<fposition>100</fposition>
<flength>99</flength>
<line>5</line>
</message>
xml2
====
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE message SYSTEM "message.dtd">
<message>
<fposition>100</fposition>
<flength>99</flength>
<line>5</line>
</message>
Any help or suggestions would be appreciated.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
