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/01/03 17:49:36 UTC
DO NOT REPLY [Bug 5675] New: -
use of setExternalSchemaLocation() yields inconsistent behavior
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=5675>.
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=5675
use of setExternalSchemaLocation() yields inconsistent behavior
Summary: use of setExternalSchemaLocation() yields inconsistent
behavior
Product: Xerces-C++
Version: 1.6.0
Platform: PC
OS/Version: Windows NT/2K
Status: NEW
Severity: Major
Priority: Other
Component: Validating Parser (Schema) (Xerces 1.5 or up only)
AssignedTo: xerces-c-dev@xml.apache.org
ReportedBy: tdodd@iss.net
The gist of this bug is that I get different (erroneous) behavior depending on
the contents of the string I feed to setExternalSchemaLocation(). If I don't
use setExternalSchemaLocation(), and let the parser find the schemas through
the schema locations specified internally in the document, the parse succeeds.
If I list the "master" schema (the schema that imports the other ("child")
schema) first in the external schema location string, or omit the the "child"
schema, the parse will succeed. If I list the "child" schema before
the "master" schema in the external schema location string, the parse fails. I
have determined that this is because when the parser reaches line 282 of
SchemaInfo.hpp (SchemaInfo::getImportInfo()), the import list (fImportList) is
empty. The error is from line 4, column 38 of test.xml: "Prefix: 'barney' can
not be resolved to a URI."
Here's the code that shows 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;
}
// When the schemas are listed in this order, the test document parse fails.
LPCWSTR wszBadSchemaLocation = L"\
http://www.fred.com/common ./barney.xsd \
http://www.fred.com/test ./test.xsd";
// When the schemas are listed in this order, the test document parses properly.
LPCWSTR wszGoodSchemaLocation1 = L"\
http://www.fred.com/test ./test.xsd \
http://www.fred.com/barney ./barney.xsd";
// When the "barney" namespace is omitted, the test document parses properly.
LPCWSTR wszGoodSchemaLocation2 = L"\
http://www.fred.com/test ./test.xsd";
int wmain(int argc, wchar_t* argv[])
{
if (argc != 2)
{
std::wcout << L"Usage is: XmlParse <filename>" << std::endl;
}
else
{
try
{
DOMParser parser;
// Configure parser for a validating parse.
parser.setErrorHandler(&ErrHandler);
parser.setIncludeIgnorableWhitespace(false);
parser.setDoSchema(true);
parser.setValidationScheme(DOMParser::Val_Auto);
parser.setDoNamespaces(true);
parser.setCreateEntityReferenceNodes(false);
parser.setToCreateXMLDeclTypeNode(false);
// Letting the parser use the internal schema locations works.
parser.parse(LocalFileInputSource(argv[1]));
std::wcout << L"File '" << argv[1] << L"' parsed successfully using
internal schema locations." << std::endl;
// This external schema specification works.
parser.setExternalSchemaLocation(wszGoodSchemaLocation1);
parser.parse(LocalFileInputSource(argv[1]));
std::wcout << L"File '" << argv[1] << L"' parsed successfully using
(first version) external schema locations." << std::endl;
// This external schema specification works.
parser.setExternalSchemaLocation(wszGoodSchemaLocation2);
parser.parse(LocalFileInputSource(argv[1]));
std::wcout << L"File '" << argv[1] << L"' parsed successfully using
(second version) external schema locations." << std::endl;
// This one doesn't work.
parser.setExternalSchemaLocation(wszBadSchemaLocation);
parser.parse(LocalFileInputSource(argv[1]));
std::wcout << L"File '" << argv[1] << L"' parsed successfully using
(third version) external schema locations." << std::endl;
}
catch (const CMyException& e)
{
std::wcout << e << std::endl;
}
}
return 0;
}
---
Here's the test document (test.xml):
---
<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<root xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.fred.com/test ./test.xsd'
xmlns='http://www.fred.com/test'>
<child>empty-value</child>
</root>
---
Here is the "master" schema (test.xsd):
---
<schema xmlns='http://www.w3.org/2001/XMLSchema'
targetNamespace='http://www.fred.com/test'
xmlns:barney='http://www.fred.com/barney'
xmlns:test='http://www.fred.com/test'
elementFormDefault='qualified'
version='1.0'>
<import namespace='http://www.fred.com/barney'
schemaLocation='./barney.xsd'/>
<complexType name='TestType'>
<sequence>
<element name='child' type='barney:TestValue' minOccurs='0'
maxOccurs='unbounded'/>
</sequence>
</complexType>
<element name='root' type='test:TestType'/>
</schema>
---
Here is the "child" schema (barney.xsd):
---
<schema xmlns='http://www.w3.org/2001/XMLSchema'
targetNamespace='http://www.fred.com/barney'
xmlns:barney='http://www.fred.com/barney'
elementFormDefault='qualified'
version='1.0.0'>
<simpleType name='TestValue'>
<restriction base='normalizedString'>
<enumeration value='value-1'/>
<enumeration value='value-2'/>
<enumeration value='value-3'/>
<enumeration value='empty-value'/>
</restriction>
</simpleType>
</schema>
---
Put the schemas in the same folder as the input document, and set this folder
as your project's working directory. If you wish, I can zip my entire VC++
project up and send it to you.
Thanks,
Tim Dodd
Software Engineer
Internet Security Systems
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org