Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Problem Validating XML Document [Thread Next] Re: Problem Validating XML DocumentTo: NULL Date: 1/14/2009 5:19:00 AM Hi Martin, Thanks for your help. I used MSXML6 and was able to successfully validate the XML before writing it out. Regards, Martin "Martin Honnen" wrote: > 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/ > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
