public class XmlSchemaComplexContent : XmlSchemaContentModel
|
using System;
using System.Xml;
using System.Xml.Schema;
class XMLSchemaExamples {
public static void Main() {
XmlSchema schema = new XmlSchema();
// <xs:complexType name="address">
XmlSchemaComplexType address = new XmlSchemaComplexType();
schema.Items.Add(address);
address.Name = "address";
// <xs:sequence>
XmlSchemaSequence sequence = new XmlSchemaSequence();
address.Particle = sequence;
// <xs:element name="name" type="xs:string"/>
XmlSchemaElement elementName = new XmlSchemaElement();
sequence.Items.Add(elementName);
elementName.Name = "name";
elementName.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:element name="street" type="xs:string"/>
XmlSchemaElement elementStreet = new XmlSchemaElement();
sequence.Items.Add(elementStreet);
elementStreet.Name = "street";
elementStreet.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:element name="city" type="xs:string"/>
XmlSchemaElement elementCity = new XmlSchemaElement();
sequence.Items.Add(elementCity);
elementCity.Name = "city";
elementCity.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:complexType name="USAddress">
XmlSchemaComplexType USAddress = new XmlSchemaComplexType();
schema.Items.Add(USAddress);
USAddress.Name = "USAddress";
// <xs:complexContent>
XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();
USAddress.ContentModel = complexContent;
// <xs:extension base="address">
XmlSchemaComplexContentExtension extensionAddress = new XmlSchemaComplexContentExtension();
complexContent.Content = extensionAddress;
extensionAddress.BaseTypeName = new XmlQualifiedName("address");
// <xs:sequence>
XmlSchemaSequence sequence2 = new XmlSchemaSequence();
extensionAddress.Particle = sequence2;
// <xs:element name="state" type="xs:string"/>
XmlSchemaElement elementUSState = new XmlSchemaElement();
sequence2.Items.Add(elementUSState);
elementUSState.Name = "state";
elementUSState.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:element name="zipcode" type="xs:positiveInteger"/>
XmlSchemaElement elementZipcode = new XmlSchemaElement();
sequence2.Items.Add(elementZipcode);
elementZipcode.Name = "zipcode";
elementZipcode.SchemaTypeName = new XmlQualifiedName("positiveInteger", "http://www.w3.org/2001/XMLSchema");
schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
schema.Write(Console.Out, nsmgr);
}
public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {
Console.WriteLine(args.Message);
}
}
The following XML file is generated for the preceding code example.
<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="address">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="USAddress">
<xs:complexContent mixed="false">
<xs:extension base="address">
<xs:sequence>
<xs:element name="state" type="xs:string"/>
<xs:element name="zipcode" type="xs:positiveInteger"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
| ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
| Annotation (inherited from System.Xml.Schema.XmlSchemaAnnotated) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation Gets or sets the annotation property. |
| Content | Read-write Overridden: Gets or sets the content. |
| Id (inherited from System.Xml.Schema.XmlSchemaAnnotated) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id Gets or sets the string id. |
| IsMixed | Read-write Gets or sets information that determines if the type has a mixed content model. |
| LineNumber (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber Gets or sets the line number in the file to which the schema element refers. |
| LinePosition (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition Gets or sets the line position in the file to which the schema element refers. |
| Namespaces (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces |
| SourceUri (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri Gets or sets the source location for the file that loaded the schema. |
| UnhandledAttributes (inherited from System.Xml.Schema.XmlSchemaAnnotated) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes Gets or sets the qualified attributes that do not belong to the schema target namespace. |
| Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
| GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
| GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
| ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
| Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
| MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public XmlSchemaComplexContent(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public override XmlSchemaContent Content {get; set;}
|
public string Id {get; set;}
|
Optional.
public bool IsMixed {get; set;}
|
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public string SourceUri {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
~XmlSchemaComplexContent(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |