Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: DOM/SOM MSXML4 - How to get the appinfo of an XSD-Element

From: "Martin Schmeller" <martin.schmeller@------.--->
To: NULL
Date: 4/1/2005 3:18:00 PM
Thanks a lot !!!

What a trick :)

Greetings

Martin

"Martin Honnen" <mahotrash@y...> schrieb im Newsbeitrag
news:OW0U4TrNFHA.3772@T......
>
>
> Martin Schmeller wrote:
>
>
> > I need to know how I can get the appinfo of an XSD-Element.
> > I user msxml4 and VB6.
> > Is there a way with the DOM/SOM object model?
>
> The solution is a bit odd in my view but the information in annotations
> in a schema element is exposed by allowing to write the annotation to a
> new XML DOM document for instance, using the method writeAnnotation.
> Then you can use normal DOM and/or XPath to access appinfo or
> documentation as needed.
>
> Here is a simple example using JScript, the XML document just has a root
> element:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <GOD
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:noNamespaceSchemaLocation="test2005040101Xsd.xml">Kibo</GOD>
>
> the schema for that is
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema
>    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>    version="1.0">
>
> <xs:element name="GOD" type="xs:string" fixed="Kibo">
>    <xs:annotation>
>      <xs:appinfo>The one and only.</xs:appinfo>
>    </xs:annotation>
> </xs:element>
>
> </xs:schema>
>
> the example JScript creates a DOMDocument and parses the XML file, then
> it gets the schema item defining the root element using the
> getDeclaration method, creates a new empty DOMDocument and calls the
> writeAnnotation method to fill it with the annotation info from the
> schema element. Then XPath is used to read out the text content of the
> first xs:appinfo element.
>
> var xmlDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
> xmlDocument.async = false;
> var valid = xmlDocument.load('test2005040101.xml');
>
> if (valid) {
>    var rootElementType =
> xmlDocument.namespaces.getDeclaration(xmlDocument.documentElement);
>    var annotationDocument = new ActiveXObject('Msxml2.DOMDocument.4.0');
>    rootElementType.writeAnnotation(annotationDocument);
>    annotationDocument.setProperty('SelectionNamespaces',
> 'xmlns:xs="http://www.w3.org/2001/XMLSchema"');
>    alert(annotationDocument.selectSingleNode('//xs:appinfo').text);
> }
> else {
>    alert(xmlDocument.parseError.reason);
> }
>
> -- 
>
> 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