Microsoft KB Archive/307935

= HOW TO: Use the ms:type-is XPath Extension Function to Program the MSXML DOM in Visual Basic for Windows =

Article ID: 307935

Article Last Modified on 10/27/2002

-

APPLIES TO


 * Microsoft XML Core Services 4.0
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q307935





IN THIS TASK
SUMMARY
 * Description of the ms:type-is XPath Extension Function
 * Create the Sample XML Document
 * Create the Sample XSD Document
 * Create and Test the Visual Basic Project

REFERENCES



SUMMARY
This step-by-step article describes how to use the ms:type-is XPath extension function to program the MSXML 4.0 Document Object Model (DOM) in Visual Basic.

back to the top

Description of the ms:type-is XPath Extension Function
The XPath implementation in MSXML 4.0 introduces a set of XSD extension functions that can specify expressions that evaluate nodes based on their data type. The ms:type-is XPath extension function can identify nodes of a specified data type (as defined in an associated XSD schema) in an XML document.

You must supply 2 parameters when you use the ms:type-is XPath extension function:
 * The namespace Uniform Resource Identifier (URI) for the data type against which a node's data type is to be evaluated.
 * The local name of the data type.

back to the top

Create the Sample XML Document
Use Notepad to create and save an XML document named Books.xml that contains the following XML:   Adams NC XML Developer's Guide Computer 44.95      2000-10-01 An in-depth look at creating applications with XML.  Books.xml references an XSD schema document called Books.xsd that defines its structure.

back to the top

Create the Sample XSD Document
  Use Notepad to create an XSD schema document named Books.xsd that contains the following code: 



 <xs:sequence> <xs:element name=&quot;book&quot; type=&quot;b:bookdata&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;/> </xs:sequence> </xs:complexType>

<xs:simpleType name=&quot;AuthorType&quot;> <xs:restriction base=&quot;xs:string&quot;> <xs:maxLength value=&quot;5&quot;/> </xs:restriction> </xs:simpleType>

<xs:complexType name=&quot;bookdata&quot;> <xs:sequence> <xs:element name=&quot;author&quot; type=&quot;b:AuthorType&quot;/> <xs:element name=&quot;State&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;title&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;genre&quot; type=&quot;xs:string&quot;/> <xs:element name=&quot;price&quot; type=&quot;xs:float&quot;/> <xs:element name=&quot;publish_date&quot; type=&quot;xs:date&quot;/> <xs:element name=&quot;description&quot; type=&quot;xs:string&quot;/> </xs:sequence>

<xs:attribute name=&quot;id&quot; type=&quot;xs:string&quot;/>

</xs:complexType>

</xs:schema> </li> <li>Save Books.xsd in the same folder in which you saved Books.xml.</li></ol>

back to the top

Create and Test the Visual Basic Project
<ol> <li>In Visual Basic 6.0, create a new Standard EXE project. Form1 is created by default.</li> <li>Add a project reference to Microsoft XML, version 4.0.</li> <li>Drag a command button onto Form1.</li> <li> Paste the following code in the Click event procedure of the command button, and specify the path to Books.xml in the xmldom.Load statement: Dim xmldom As MSXML2.DOMDocument40 Set xmldom = New MSXML2.DOMDocument40

xmldom.async = False xmldom.setProperty &quot;SelectionNamespaces&quot;, &quot;xmlns:ms='urn:schemas-microsoft-com:xslt'&quot; xmldom.Load &quot;<Path to Books.xml>&quot;

Set nlist = xmldom.selectNodes(&quot;//*[ms:type-is('http://www.w3.org/2001/XMLSchema','float')]&quot;)

Dim node As MSXML2.IXMLDOMNode For Each node In nlist Debug.Print node.nodeName Next The selectNodes method of the DOMDocument object specifies an XPath expression that uses the ms:type-is extension function to identify all of the nodes of the XSD float data type.

</li> <li>Save and run the project.</li> <li>Click the command button when the form is displayed to run the XPath query and display the name or names of the matching nodes. The price element in Books.xml is the only node whose data type is XSD float. The name of this node (price) is displayed in the Visual Basic Immediate window when the code is run.</li></ol>

back to the top

<div class="references_section">