Finding Child Elements of Top-Level XML Schema Elements


[This topic discusses a feature that was only implemented for MSXML 6.0.]

SOM elements that are returned from interface properties originate at the top level of the XML Schema. Top-level elements of an XML Schema are declarations that are not nested inside other declarations.


The following example shows a top-level <ComplexType> declaration that contains a second-level <element> declaration.

XML Schema: childsample.xsd

<schema xmlns = "">  
    <complexType name = "TopLevelType">  
        <element name = "SecondLevelElement"/>  

To navigate through the schema to the secondary and lower child items, you must use the contentModel property of the ISchemaComplexType interface. This property returns a SchemaModelGroup object. The particles property of the ISchemaModelGroup interface returns a collection of elements, modelGroup objects, and any declarations that are in the <complexType> declaration of the parent element.


In the following example, the schema above, childsample.xsd, is queried from a Visual Basic program.

Dim oSchemaCache as New XMLSchemaCache60  
Dim oSchema as ISchema  
Dim nsTarget as String  
nsTarget = ""  
oSchemaCache.add nsTarget, "childsample.xsd"  
Set oSchema = oSchemaCache.getSchema
Set oComplexTypes = oSchema.types  
Set oContentModelGroup = oComplexTypes
Set oChildItems = oContentModelGroup.particles  
strElementName = oChildItems


When you use the DOM to find child items, you can go directly to the node you want. With the SOM, however, you must start with a top-level item and drill down through the child elements until you reach the node you want.

See Also

SOM Concepts
Complex Type Definitions
Defining Complex Types