Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Accessing XSD definition (including metadata) when walking through an XML instance

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 4/8/2009 1:51:00 PM
Yo/\ek wrote:

> xml_doc = new ActiveXObject("Microsoft.XMLDOM");

First note that Microsoft.XMLDOM is outdated, if you want to have W3C 
XML schema support then you need to use MSXML 6 (recommended) or at 
least MSXML 4.
Then the schema is not exposed as an XML DOM document but rather as 
instances of the SOM (schema object model).

Here is a quick example:

test2009040801.xml:

<root>
   <foo>foo 1</foo>
</root>

test2009040801Xsd.xml

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

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

</xs:schema>

JScript:

var doc = new ActiveXObject('Msxml2.DOMDocument.6.0');
var schemaCache = new ActiveXObject('Msxml2.XMLSchemaCache.6.0');
schemaCache.add('', 'test2009040801Xsd.xml');
doc.schemas = schemaCache;
doc.async = false;
doc.validateOnParse = true;
if (doc.load('test2009040801.xml'))
{
   var schemaItem = doc.namespaces.getDeclaration(doc.documentElement);
   WScript.Echo(schemaItem.name);
}
else
{
   WScript.Echo(doc.parseError.reason);
}

Output:
root


The MSXML SDK with documentation of the SOM (schema object model) is 
online here:
http://msdn.microsoft.com/en-us/library/ms763742(VS.85).aspx

It is also available for download where you get a .chm that is quicker 
to use and navigate than the online version.

As the W3C XML schema language is rather complex so is the SOM so take 
your time to get familiar with all those types. For instance there is a 
writeAnnotation method
http://msdn.microsoft.com/en-us/library/ms766478(VS.85).aspx
that allows you to write the annotion in an ISchemaItem to a DOM node.





-- 

	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