Search code examples
c#xmlxsdxmlschemaset

XmlSchemaElement class properties meaning


Maybe I missed something, but can anyone explain to me the meaning and differences of the following properties of XmlSchemaElement class:

  1. What are the differences between XmlSchemaElement.ElementSchemaType and XmlSchemaElement.ElementType?
  2. What are the differences between QualifiedName, SchemaTypeName and RefName?
  3. How QualifiedName, SchemaTypeName and RefName are related to each other? When SchemaTypeName.IsEmpty == true, does it mean that RefName.IsEmpty == false?
  4. Is it possible that all *Names will be Empty, what does it mean, an embedded ComplexType?

In general I need to parse xsd and map the result to internal structure, so I need some rules, which allows me to generate different types of object. Let's say if (SchemaTypeName.IsEmpty) then in ElementSchemaType I have SimpleType with all the restrictions provided.


Solution

    1. XmlSchemaElement.ElementType is obsolete since 2.0, otherwise they're the same.
    2. QualifiedName represents the actual qualified name of the element, as the corresponding XML element in an XML instance document would have it. SchemaTypeName represents the name of the type given to the element (could be a built in XSD such as int or a user define type, such as mine). The RefName indicates that the particle, while being an element, is actually a reference to a globally defined element elsewhere in the schema (see below)

      <xsd:element name="Global" type="xsd:string"/>
      <xsd:group name="some">
          <xsd:sequence>
              <xsd:element name="Local" type="xsd:int"/>
              <xsd:element ref="Global" minOccurs="0"/>
          </xsd:sequence>
      </xsd:group>
      
    3. Unfortunately, not necessarily true; for e.g., if there is no type associated with the element (by default that means xsd:anyType).

    4. No, see above (anyType).

    Further, things get even more complicated. If you have element particles under a group that is not referenced anywhere in the XSD, then the funny part is that the PSVI properties of the element particle under that group don't get populated... I never bothered to figure out if that is a feature or a bug... What I did though was to build a visitor that is using all these properties and trying to process the one bit of information it finds... To me this approach also proved resilient to .NET fixes over the years...