tags:

views:

291

answers:

1

Dear All,

Good day.

I can handle a ComplexType such as:

  <xsd:element name="Prerequisite">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="Type" type="Prerequisite.Type.type" minOccurs="1" maxOccurs="1" />
        <xsd:element name="Miscellaneous" type="Prerequisite.Misc.type" minOccurs="0" maxOccurs="1" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>

My C# like this below:

    // Get the sequence particle of the complex type.
    XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence;

    if (sequence != null)
    {
        // Iterate over each XmlSchemaElement in the Items collection.
        foreach (XmlSchemaElement childElement in sequence.Items)
        {
            Console.WriteLine("Element: {0}/{1}/{2}/{3}", 
                              childElement.QualifiedName.Name,
                              childElement.SchemaTypeName.Name, 
                              childElement.MinOccurs, 
                              childElement.MaxOccurs);
        }
    }

But i don't know how to handle the "restriction" and "enumeration"? Could you please give me some guide. thanks in advance.

  <xsd:simpleType name="SystemTypeEnum">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Etch" />
    </xsd:restriction>
  </xsd:simpleType>

XmlSchemaSequence -> I Can't find the class of XmlSchemaRestriction

XmlSchemaElement -> I Can't find the class of XmlSchemaEnumeration too.

:-(

========================= Need Further Help. THANKS. ========================

@ foreach (XmlSchemaEnumerationFacet childEnumeration in ????);

I still don't know how to complete the top line. Could you give me further help?

        XmlSchemaSimpleType simpleType = xsdType as XmlSchemaSimpleType;
        Console.WriteLine("simpleType: {0}", xsdType.Name);
        XmlSchemaSimpleTypeRestriction restriction = simpleType.Content as XmlSchemaSimpleTypeRestriction;

        if (restriction != null)
        {

            Console.WriteLine("restriction : {0}", restriction.BaseTypeName.Name);

            foreach (XmlSchemaEnumerationFacet childEnumeration in ????)
            {
                Console.WriteLine("Element: {0}", childEnumeration.Value);
            }
        }
+1  A: 

There are XmlSchemaSimpleTypeRestriction and XmlSchemaEnumerationFacet.

The question "Extract enumeration values from xsd schema file in .net" discusses the same problem.

Tomalak