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/04/12 22:52:30 UTC

DO NOT REPLY [Bug 8035] New: - specifying a schema location via setExternalSchemaLocation() causes validating parse failure

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=8035>.
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=8035

specifying a schema location via setExternalSchemaLocation() causes validating parse failure

           Summary: specifying a schema location via
                    setExternalSchemaLocation() causes validating parse
                    failure
           Product: Xerces-C++
           Version: 1.7.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


Specifying a schema location via setExternalSchemaLocation() causes a 
validating parse failure when parsing a schema.  The namespace specified in the 
schemaLocation string is not the target namespace of the schema, so the 
setExternalSchemaLocation() call should have no effect.  Commenting out the 
setExternalSchemaLocation() allows the validating parse to succeed.

Here's the code that reproduces 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;
}

int wmain(int argc, wchar_t* argv[])
{
    int nResult = 0;

    if (argc != 2)
    {
        std::wcout << L"Usage is:  XmlParse <filename>" << std::endl;
    }
    else
    {
        try
        {
            DOMParser parser;
            CMySaxErrorHandler myErrHandler;

            // Configure parser for a validating parse.
            parser.setDoSchema(true);
            parser.setValidationScheme(DOMParser::Val_Auto);
            parser.setDoNamespaces(true);
            parser.setErrorHandler(&myErrHandler);
            parser.setExternalSchemaLocation(L"http://www.fred.com/barney 
Barney.xsd");
            std::wcout << L"Parsing file " << argv[1] << L"..." << std::endl;

            parser.parse(LocalFileInputSource(argv[1]));
        }
        catch (const CMyException& e)
        {
            std::wcout << e << std::endl;
            nResult = e.GetCode();
        }
    }

	return nResult;
}
---

Here's the schema Root.xsd (this is left over from another test case; any 
schema may be used to reproduce the problem):

---
<schema targetNamespace='http://www.fred.com'
    xmlns='http://www.w3.org/2001/XMLSchema'
    xmlns:root='http://www.fred.com'
    elementFormDefault='qualified'
    version='1.0.0'>

    <element name='root'>
        <complexType>
            <sequence maxOccurs='unbounded'>
                <element name='schema-content'>
                    <complexType>
                        <sequence>
                            <any namespace='http://www.w3.org/2001/XMLSchema' 
processContents='lax'/>
                        </sequence>
                    </complexType>
                </element>
            </sequence>
        </complexType>
    </element>
</schema>
---

Here's the schema Barney.xsd, specified in the setExternalSchemaLocation() 
call.  It's target namespace is not the subject of a schemaLocation specifier 
in the parsed Root.xsd schema document, and Root.xsd does not import the 
Barney.xsd's target namespace.  So the setExternalSchemaLocation() call should 
have no effect on the parse.  Again, any schema will suffice for reproducing 
the problem.

---
<schema targetNamespace='http://www.fred.com/barney'
    xmlns='http://www.w3.org/2001/XMLSchema'
    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>
---

Running the program, specifying Root.xsd as the input file yields (again, any 
schema may be used as the input; you'll get the same error):

---
Parsing file Root.xsd...
Parse operation:  Error parsing file "C:\XmlTest\Root.xsd",
line 5, column 21
   Message: Unknown element 'schema'
---

Commenting out the setExternalSchemaLocation() call avoids the error.  The 
problem only occurs when trying to parse a .xsd file.  Parsing a regular .xml 
file, and specifying an unrelated namespace in a setExternalSchemaLocation() 
call does not cause the validating parse to fail.

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org