How to get a XmlSchemaObject by it's SchemaTypeName

J

Jim

Maybe I'm missing something obvious, but I'm stumped
right now. I'm trying to retrieve, in this case, a
XmlSchemaComplexType object (MyElementId) from the myelem
particle. Basically, I would like to retrieve an item
from the schema object based on the objects
QualifiedName/SchemaTypeName. When I traverse the items
defined in the schema object, their QualifiedName objects
are not defined (empty).


So I tried and failed with code similar to:

private XmlSchemaComplexType ProcessParticle(XmlSchema
schema, XmlSchemaParticle myelemParticle)
{
if (myelemParticle is XmlSchemaElement)
{
foreach (XmlSchemaObject o in schema.Items)
{
if (o is XmlSchemaComplexType)
{
// The QualifiedName is not defined for any
object...
// It is reported as empty
if (((XmlSchemaComplexType)o).QualifiedName ==
((XmlSchemaElement)particle).SchemaTypeName)
{
return (XmlSchemaComplexType) o;
}
}
}
return null;
}
}

An example schema is below:

<xs:schema
xmlns:myschema="http://schema.org/schema/myschema.xsd"
targetNamespace="http://schema.org/schema/myschema.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType id="MyElementId" name="myelement">
<xs:attribute name="anotherthing" use="optional" />
<xs:attribute name="name" use="required" />
<xs:attribute name="something" use="optional" />
</xs:complexType>
<xs:complexType id="MainElement" name="main">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="myelem"
type="myschema:myelement" />
</xs:sequence>
</xs:sequence>
<xs:attribute name="someattr" use="optional" />
</xs:complexType>
</xs:schema>


Any insight would be helpful.

Thanks

Jim
 
J

Jim

Any reason this hasn't been answered, seeing as I have an
MSDN universal subscription?
 
J

James Geurts

Yes, I have registered it. I just re-registered it, in
case if it didn't work the first time.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top