Here's an example that shows how to traverse XmlSchema object.
void Start()
{
XmlSchemaComplexType complexType;
foreach (XmlSchemaType type in xs.SchemaTypes.Values)
{
complexType = type as XmlSchemaComplexType;
if (complexType != null)
TraverseParticle(complexType.ContentTypeParticle);
}
foreach (XmlSchemaElement el in xs.Elements.Values)
TraverseParticle(el);
}
void TraverseParticle(complexType.ContentTypeParticle)
{
if (particle is XmlSchemaElement)
{
XmlSchemaElement elem = particle as XmlSchemaElement;
if (elem.RefName.IsEmpty)
{
XmlSchemaType type = (XmlSchemaType)elem.ElementSchemaType;
XmlSchemaComplexType complexType = type as XmlSchemaComplexType;
if (complexType != null && complexType.Name == null)
TraverseParticle(complexType.ContentTypeParticle);
}
}
else if (particle is XmlSchemaGroupBase)
{ //xs:all, xs:choice, xs:sequence
XmlSchemaGroupBase baseParticle = particle as XmlSchemaGroupBase;
foreach (XmlSchemaParticle subParticle in baseParticle.Items)
TraverseParticle(subParticle);
}
}
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
"SideByEach" <kn*****@nb.sympatico.ca> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
I've got a schema loaded into a XmlSchema class. Via the elements
collection I can see all the elements defiend at the root of the
schema. How can I get the definition of a nested schema element?
Thanks.