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
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