Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: MSXML 4.0 to 6.0 - Invalid Namespace And XMLSchemaCache >Thread Next - Re: MSXML 4.0 to 6.0 - Invalid Namespace And XMLSchemaCache Re: MSXML 4.0 to 6.0 - Invalid Namespace And XMLSchemaCacheTo: NULL Date: 11/12/2008 7:12:00 PM Leverd wrote:
> You can, but it will only work with the first namespace (base namespace).
> For some reason MSXML will not signal an error on any namespace declarations
> after that.
I can't reproduce the problem.
Here is the schema file test2008111201Xsd.xml:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/2008/ns1"
elementFormDefault="qualified"
xmlns:pf2="http://example.com/2008/ns2">
<xs:import namespace="http://example.com/2008/ns2"
schemaLocation="test2008111202Xsd.xml"/>
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element name="foo">
<xs:complexType>
<xs:sequence>
<xs:element ref="pf2:bar"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Here is the schema file test2008111202Xsd.xml:
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/2008/ns2"
elementFormDefault="qualified">
<xs:element name="bar" type="xs:int"/>
</xs:schema>
Here is an XML instance document named test2008111201.xml:
<pf1:root xmlns:pf1="http://example.com/2008/ns1">
<pf1:foo xmlns:pf2="http://example.com/2008/ns3">
<pf2:bar>foobar</pf2:bar>
</pf1:foo>
</pf1:root>
Here is some JScript code using MSXML 6 to validate the instance document:
var ver = '6.0';
var schemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.' + ver);
schemaCache.add('http://example.com/2008/ns1', 'test2008111201Xsd.xml');
schemaCache.add('http://example.com/2008/ns2', 'test2008111202Xsd.xml');
var doc = new ActiveXObject('Msxml2.DOMDocument.' + ver);
doc.async = false;
doc.schemas = schemaCache;
doc.validateOnParse = true;
if (doc.load('test2008111201.xml'))
{
"valid"
}
else
{
doc.parseError.reason
}
It outputs an error message, the original is in German here on my system:
"Der Inhalt des Elements '{http://example.com/2008/ns3}bar' ist gemäß
dem Inhaltsmodell des übergeordneten Elements
'{http://example.com/2008/ns1}foo' nicht gültig.
Erwartet: {http://example.com/2008/ns2}bar."
Translating that as:
"The content of the element '{http://example.com/2008/ns3}bar' is not
valid according to the content model of the parent element
'{http://example.com/2008/ns1}foo'.
Expecting: {http://example.com/2008/ns2}bar."
So MSXML 6 clearly complains that the schema defines an element named
bar in the namespace http://example.com/2008/ns2 as the child of the foo
element and that the instance contains an element from a different
namespace.
MSXML 4 gives a shorter error message
"Element content is invalid according to the DTD/Schema.
Expecting: {http://example.com/2008/ns2}bar."
but that too finds the same problem.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
