![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - DOM/SOM MSXML4 - How to get the appinfo of an XSD-Element >Thread Next - Re: DOM/SOM MSXML4 - How to get the appinfo of an XSD-Element Re: DOM/SOM MSXML4 - How to get the appinfo of an XSD-ElementTo: NULL Date: 4/1/2005 2:19:00 PM 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/ | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
