Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Accessing XSD definition (including metadata) when walking through an XML instance >Thread Next - Re: Accessing XSD definition (including metadata) when walking through an XML instance Re: Accessing XSD definition (including metadata) when walking through an XML instanceTo: 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/
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
