[Home] [By Thread] [By Date] [Recent Entries]


Thanks! I am glad to hear MSXML allows this to be detected.

Now suppose I change example.xml to:

<bar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="bar.xsd"/>

where bar.xsd is:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="bar">
  <xs:complexType/>
</xs:element>

</xs:schema>

Is there also some way to tell MSXML not to allow the instance to provide
additional schemas so that this would be detected as invalid as well?

James

----- Original Message -----
From: "Dare Obasanjo" <dareo@m...>
To: "James Clark" <jjc@j...>; "Simon St.Laurent"
<simonstl@s...>; <xml-dev@l...>
Sent: Wednesday, June 05, 2002 11:55 AM
Subject: RE:  Interesting mailing list & a rare broadside


> Changing the code to
>
>   var schemas = new ActiveXObject("MSXML2.XMLSchemaCache.4.0");
>   schemas.add("http://www.example.org", "cyclic.xsd");
>
>   var x = new ActiveXObject("MSXML2.DOMDocument.4.0");
>   x.async = false;
>   x.schemas = schemas;
>   x.validateOnParse = false; /* don't validate on parse */
>   x.load("example.xml");
>
>   var vError = x.validate(); /* validate, grabbing error object (if any)
> */
>
>   /* print error message */
>   if(vError.reason != "")
>     WScript.Echo("invalid: " + vError.reason);
>   else
>     WScript.Echo("valid");
>
> Leads to "invalid: Validate failed because the root element had no
> associated DTD/schema" being displayed. Changing the instance to
>
>    <foo  xmlns="http://www.example.com"/>
>
> results in successful validation.
>
> --
> PITHY WORDS OF WISDOM
> Never eat yellow snow.
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
>
>
> > -----Original Message-----
> > From: James Clark [mailto:jjc@j...]
> > Sent: Tuesday, June 04, 2002 9:31 PM
> > To: Dare Obasanjo; Simon St.Laurent; xml-dev@l...
> > Subject: Re:  Interesting mailing list & a rare broadside
> >
> >
> >
> > > > I'm not sure how many people read those messages
> > directly, but I'd
> > > > certainly be unhappy if <bar /> got past the validator when I was
> > > > expecting <foo /> as in Clark's point 7.
> > >
> > > Both the XmlValidatingReader in the .NET framework and MSXML will
> > > throw errors because no type definition exists for the <bar />
> > > element.
> >
> > One of the parsers I tried it with was the latest version of
> > MSXML (which I generally find to be excellent, BTW).
> >
> > Here's example.xml:
> >
> > <bar/>
> >
> > Here's example.xsd:
> >
> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> >   elementFormDefault="qualified"
> >   xmlns="http://www.example.com"
> >   targetNamespace="http://www.example.com">
> >
> > <xs:element name="foo">
> >   <xs:complexType/>
> > </xs:element>
> >
> > </xs:schema>
> >
> > Here's the example.js I used to perform the validation:
> >
> > var schemas = new ActiveXObject("MSXML2.XMLSchemaCache.4.0");
> > schemas.add("http://www.example.com", "example.xsd");
> >
> > var x = new ActiveXObject("MSXML2.DOMDocument.4.0");
> > x.async = false;
> > x.schemas = schemas;
> > x.validateOnParse = true;
> > x.load("example.xml");
> > if (x.parseError.errorCode != 0)
> >   WScript.Echo("invalid: " + x.parseError.reason);
> > else
> >   WScript.Echo("valid");
> >
> > When I run example.js, it says "valid".  Note that if you add
> > xmlns="http://www.example.com" to <bar/>, then it does report
> > it as invalid.
> >
> > Is there something else I should have done to make it report
> > the example as invalid?
> >
> > James
> >
> >
> >
> >
> >
>
>
>


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member