Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: Accessing XSD definition (including metadata) when walking through an XML instance Accessing XSD definition (including metadata) when walking through an XML instanceTo: NULL Date: 4/8/2009 4:05:00 AM Dear all,
I am trying to manage with some xml metadata in server side javascript
(old school .asp pages).
The metadata will be located in the XSD's annotation/appinfo elements.
This schema validates the XML instance.
Now, as I walk through my XML instance (using XMLDOM's selectSingleNode
() for instance), I'd like to access to the metadata related to the
current node.
Apparently, the ".definition" property allows this but I can't make
this work with an XSD schema.
It does work with an XDR schema but that is not the format I'm
supposed to use...
The following sample works great but the same with an XSD instead of
XDR fails...
Error code: -1072897791
Error reason: Error opening input file: 'Product.xsd'.
Incorrect definition for the root element in schema.
Error srcText: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
Is it just not possible to do it with a XSD ?
Is there another way to access to the xsd definition of a given node ?
Maybe the "x-schema:" prefix only applies for XDR but I found only
very little information about this syntax...
Is there a way to tell the XMLDOM that the schema is in XSD and not
XDR ?
Note that I tried with the ".schemas" property (which is actually good
for validating with XSD) but in that case, the ".definition" property
of the nodes remains null... unless I did a mistake...
Thanks in advance for any clue.
Regards,
Olivier
----------------------------------------------------------------
Product-xdr.xml :------
<?xml version="1.0" encoding="utf-8" ?>
<Product ProductID="123" xmlns="x-schema:Product.xdr">
<ProductName>Rugby jersey</ProductName>
</Product>
Product.xdr :------
<?xml version="1.0" encoding="UTF-8"?>
<Schema name="ProductSchema"
xmlns="urn:schemas-microsoft-com:xml-data"
xmlns:dt="urn:schemas-microsoft-com:datatypes">
<AttributeType name="ProductID" dt:type="int"/>
<ElementType name="ProductName" dt:type="string"/>
<ElementType name="Product" content="eltOnly">
<attribute type="ProductID" required="yes"/>
<element type="ProductName"/>
</ElementType>
</Schema>
test.js : ------ (I'm using WScript to mock-up before actually putting
it on .asp)
xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.load("Product-xdr.xml");
if (xml_doc.parseError.errorCode!=0) {
s = [];
s.push("Error code: " + xml_doc.parseError.errorCode);
s.push("Error url: " + xml_doc.parseError.url);
s.push("Error reason: " + xml_doc.parseError.reason);
s.push("Error srcText: " + xml_doc.parseError.srcText);
s.push("Error line: " + xml_doc.parseError.line);
WScript.echo(s.join('\n'));
WScript.Quit();
}
var node = xml_doc.documentElement;
WScript.echo(node.definition.xml);
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
