Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Validate xml files using MSXML schemacache [Thread Next] Re: Validate xml files using MSXML schemacacheTo: NULL Date: 11/1/2004 10:04:00 AM Martin:
Thanks for the reply. I liked your example and thought it was clear and
funny.
I see the empty string in the namespace when adding the xsd to the cache.
My only problem is, the second part of the question was not answered and I
think I know why.
The second part of the question is, "Does the collection automatically cycle
and attempt to apply the schema to the xml file?" I think the answer is yes,
but only if a namespace is currently in the xml document.
From the limited documentation that is available, adding 2 schemas to the
collection with a null string in the namespace variable will cause the first
schema to be replaced by the second schema. The result is that you may only
apply only one schema using the technique laid out below. (This is what I
believe from my testing.)
So, here is some clarity:
* I need to cycle through thousands of xml documents in a directory and
apply the correct schema to each document to check for validity before
writing the file to a database.
* Some files are of different types, but share the same root node. (This is
a version difference, not noted in the file.)
* No namespaces are available in the xml files.
Do you have any ideas?
Thanks.
rob
"Martin Honnen" wrote:
>
>
> rlieving wrote:
>
> > Can anyone point me to some documentation on validating very simple xml files
> > that do not have namespaces in them? I am using MSXML V5.0 and the parser
> > always validates the file, regardless of the Schema loaded into the cache.
>
> Here is an example, the XML (test2004103002.xml) is
>
> <?xml version="1.0" encoding="UTF-8"?>
> <gods>
> <god name="Kibo" />
> <devil name="Xibo" />
> </gods>
>
> the XML schema is (test2004103002Xsd.xml) is
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> version="1.0">
>
> <xs:element name="gods">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="god" maxOccurs="unbounded" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
>
> <xs:element name="god">
> <xs:complexType>
> <xs:attribute name="name" type="xs:string" />
> </xs:complexType>
> </xs:element>
>
> </xs:schema>
>
> and here is some JScript code checking that file
>
> var schemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.5.0');
> schemaCache.add('', 'test2004103002Xsd.xml');
>
> var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.5.0');
> xmlDocument.async = false;
> xmlDocument.schemas = schemaCache;
>
> var valid = xmlDocument.load('test2004103002.xml');
>
> if (valid) {
> alert('valid');
> }
> else {
> alert(xmlDocument.parseError.reason);
> }
>
> As the XML is not valid the error is displayed.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/
>
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
