Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: MSXML 4.0 to 6.0 - Invalid Namespace And XMLSchemaCache

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent