Finding Child Elements of Top-Level XML Schema Elements

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - SOM Developer's Guide

Finding Child Elements of Top-Level XML Schema Elements

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.

Example

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

XML Schema: childsample.xsd

<schema xmlns = "http://www.w3.org/2001/XMLSchema">
    <complexType name = "TopLevelType">
   <all>
        <element name = "SecondLevelElement"/>
   </all>
    </complexType>
</schema>

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.

Example

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

Dim oSchemaCache as New XMLSchemaCache50
Dim oSchema as ISchema
Dim nsTarget as String
nsTarget = "http://www.samples.microsoft.com/sampletarget"
oSchemaCache.add nsTarget, "childsample.xsd"
Set oSchema = oSchemaCache.getSchema(nsTarget)
Set oComplexTypes = oSchema.types
Set oContentModelGroup = oComplexTypes(0).contentModel
Set oChildItems = oContentModelGroup.particles
strElementName = oChildItems(0).Name
Note   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

Concepts | Complex Type Definitions | Defining Complex Types