Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Validate xml files using MSXML schemacache

From: rlieving@-----------.---------.---
To: 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/
> 


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