Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Problem Validating XML Document

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 1/14/2009 2:01:00 PM
MartinL wrote:

> I am creating an XML document in MSXML5 and attempting to validate it after 
> I've completed it.  Validating the document fails with an error code of 
> -1072897500 and the message "The node is neither valid nor invalid because no 
> DTD/Schema declaration was found."  Oddly, if I save the XML document and 
> read it back in again, it validates.  Some sample code that produces this 
> behavior is below, along with the xsd file.  Can someone help resolve this 
> issue?

I have now looked at the details and MSXML 5 and MSXML 6 behave 
unfortunately quite different.
With MSXML 6 and the validate method I get the correct result with the 
following samples:
Schema test2009011401Xsd.xml:

<xs:schema
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   targetNamespace="http://example.com/2009/ns1"
   elementFormDefault="qualified">

   <xs:element name="root">
     <xs:complexType>
       <xs:sequence maxOccurs="unbounded">
         <xs:element name="foo" type="xs:int"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>

</xs:schema>

VBScript using MSXML 6:

Const ns1 = "http://example.com/2009/ns1"
Dim doc : Set doc = CreateObject("Msxml2.DOMDocument.6.0")
Dim root : Set root = doc.createNode(1, "root", ns1)
Dim foo : Set foo = doc.createNode(1, "foo", ns1)
foo.text = "1"
root.appendChild foo
doc.appendChild root

Dim schemas : Set schemas = CreateObject("Msxml2.XMLSchemaCache.6.0")
schemas.add ns1, "test2009011401Xsd.xml"
Set doc.schemas = schemas

Dim error : Set error = doc.validate
WScript.Echo error.errorCode & ": " & error.reason

Set foo = doc.createNode(1, "foo", ns1)
foo.text = "a"
root.appendChild foo
Set error = doc.validate
WScript.Echo error.errorCode & ": " & error.reason

outputs (error messages are in German as I am on a German Windows XP)

0:
-1072897535: Fehler beim Analysieren von 'a' als int-Datentyp.
Analyse des Elements '{http://example.com/2009/ns1}foo' mit dem Wert 'a' 
fehlgeschlagen.

so for the first validate call there is no error found (errorCode is 0) 
and for the second validate call the problem is found.

Unfortunately if I change the code to use MSXML 5

Const ns1 = "http://example.com/2009/ns1"
Dim doc : Set doc = CreateObject("Msxml2.DOMDocument.5.0")
Dim root : Set root = doc.createNode(1, "root", ns1)
Dim foo : Set foo = doc.createNode(1, "foo", ns1)
foo.text = "1"
root.appendChild foo
doc.appendChild root

Dim schemas : Set schemas = CreateObject("Msxml2.XMLSchemaCache.5.0")
schemas.add ns1, "test2009011401Xsd.xml"
Set doc.schemas = schemas

Dim error : Set error = doc.validate
WScript.Echo error.errorCode & ": " & error.reason

Set foo = doc.createNode(1, "foo", ns1)
foo.text = "a"
root.appendChild foo
Set error = doc.validate
WScript.Echo error.errorCode & ": " & error.reason

then the result is (messages are in German as I am on a German Windows XP)

-1072897500: Der Knoten ist weder gültig noch ungültig, weil keine 
DTD/Schema-Deklaration vorhanden ist.

-1072897500: Der Knoten ist weder gültig noch ungültig, weil keine 
DTD/Schema-Deklaration vorhanden ist.

So MSXML 5 complains it does not have a schema or DTD for the node 
although the schemas property has been set.

I am not sure how to fix that other than to suggest to use MSXML 6 
instead of MSXML 5.


-- 

	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