XmlSchemaComplexType 類別

定義

將來自 XML 結構描述的 complexType 項目依 World Wide Web Consortium (W3C) 規定表示。 這個類別 (Class) 定義決定元素屬性 (Attribute) 集和內容的複雜類型。

public ref class XmlSchemaComplexType : System::Xml::Schema::XmlSchemaType
public class XmlSchemaComplexType : System.Xml.Schema.XmlSchemaType
type XmlSchemaComplexType = class
    inherit XmlSchemaType
Public Class XmlSchemaComplexType
Inherits XmlSchemaType
繼承

範例

下列範例會 complexType 建立 專案。

#using <mscorlib.dll>
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

class XmlSchemaExamples
{
public:

    static void Main()
    {
        XmlSchema^ schema = gcnew XmlSchema();

        // <xs:element name="stringElementWithAnyAttribute">
        XmlSchemaElement^ element = gcnew XmlSchemaElement();
        schema->Items->Add(element);
        element->Name = "stringElementWithAnyAttribute";

        // <xs:complexType>
        XmlSchemaComplexType^ complexType = gcnew XmlSchemaComplexType();
        element->SchemaType = complexType;

        // <xs:simpleContent>
        XmlSchemaSimpleContent^ simpleContent = gcnew XmlSchemaSimpleContent();
        complexType->ContentModel = simpleContent;

        // <extension base= "xs:string">
        XmlSchemaSimpleContentExtension^ extension = gcnew XmlSchemaSimpleContentExtension();
        simpleContent->Content = extension;
        extension->BaseTypeName = gcnew XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:anyAttribute namespace="##targetNamespace"/>
        XmlSchemaAnyAttribute^ anyAttribute = gcnew XmlSchemaAnyAttribute();
        extension->AnyAttribute = anyAttribute;
        anyAttribute->Namespace = "##targetNamespace";

        XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
        schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne);
        schemaSet->Add(schema);
        schemaSet->Compile();

        XmlSchema^ compiledSchema;

        for each (XmlSchema^ schema1 in schemaSet->Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable());
        nsmgr->AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema->Write(Console::Out, nsmgr);
    }

    static void ValidationCallbackOne(Object^ sender, ValidationEventArgs^ args)
    {
        Console::WriteLine(args->Message);
    }
};

int main()
{
    XmlSchemaExamples::Main();
    return 0;
};
using System;
using System.Xml;
using System.Xml.Schema;

class XMLSchemaExamples
{
    public static void Main()
    {

        XmlSchema schema = new XmlSchema();

        // <xs:element name="stringElementWithAnyAttribute">
        XmlSchemaElement element = new XmlSchemaElement();
        schema.Items.Add(element);
        element.Name = "stringElementWithAnyAttribute";

        // <xs:complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();
        element.SchemaType = complexType;

        // <xs:simpleContent>
        XmlSchemaSimpleContent simpleContent = new XmlSchemaSimpleContent();
        complexType.ContentModel = simpleContent;

        // <extension base= "xs:string">
        XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
        simpleContent.Content = extension;
        extension.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <xs:anyAttribute namespace="##targetNamespace"/>
        XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
        extension.AnyAttribute = anyAttribute;
        anyAttribute.Namespace = "##targetNamespace";

        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }

    public static void ValidationCallbackOne(object sender, ValidationEventArgs args)
    {
        Console.WriteLine(args.Message);
    }
}
Imports System.Xml
Imports System.Xml.Schema

Class XMLSchemaExamples
    Public Shared Sub Main()

        Dim schema As New XmlSchema()

        ' <xs:element name="stringElementWithAnyAttribute">
        Dim element As New XmlSchemaElement()
        schema.Items.Add(element)
        element.Name = "stringElementWithAnyAttribute"

        ' <xs:complexType>
        Dim complexType As New XmlSchemaComplexType()
        element.SchemaType = complexType

        ' <xs:simpleContent>
        Dim simpleContent As New XmlSchemaSimpleContent()
        complexType.ContentModel = simpleContent

        ' <extension base="xs:string">
        Dim extension As New XmlSchemaSimpleContentExtension()
        simpleContent.Content = extension
        extension.BaseTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")

        ' <xs:anyAttribute namespace="##targetNamespace"/>
        Dim anyAttribute As New XmlSchemaAnyAttribute()
        extension.AnyAttribute = anyAttribute
        anyAttribute.Namespace = "##targetNamespace"

        Dim schemaSet As New XmlSchemaSet()
        AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne

        schemaSet.Add(schema)
        schemaSet.Compile()

        Dim compiledSchema As XmlSchema = Nothing

        For Each schema1 As XmlSchema In schemaSet.Schemas()
            compiledSchema = schema1
        Next

        Dim nsmgr As New XmlNamespaceManager(New NameTable())
        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
        compiledSchema.Write(Console.Out, nsmgr)

    End Sub

    Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs)
        Console.WriteLine(args.Message)
    End Sub

End Class

下列 XML 檔案用於上述程式碼範例。

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="stringElementWithAnyAttribute">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:anyAttribute namespace="##targetNamespace"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
</xs:schema>

備註

專案可以使用型別屬性來宣告,該類型屬性參考 complexType 定義該專案的結構、內容和屬性。

建構函式

XmlSchemaComplexType()

初始化 XmlSchemaComplexType 類別的新執行個體。

屬性

Annotation

取得或設定 annotation 屬性。

(繼承來源 XmlSchemaAnnotated)
AnyAttribute

取得或設定複雜型別的 XmlSchemaAnyAttribute 元件之值。

Attributes

取得複雜類型的屬性集合。

AttributeUses

取得這個複雜類型及其基底類型 (Base Type) 所有遵守之屬性的集合。

AttributeWildcard

取得這個複雜型別及其基底型別之 anyAttribute 的編譯後值。

BaseSchemaType
已過時。
已過時。
已過時。

取得編譯後物件型別或內建 XML 結構描述定義語言 (XSD) 資料型別、simpleType 項目或 complexType 項目。 這是後結構描述編譯資訊集屬性。

(繼承來源 XmlSchemaType)
BaseXmlSchemaType

取得此結構描述型別之基底型別的編譯後值。

(繼承來源 XmlSchemaType)
Block

取得或設定 block 屬性。

BlockResolved

取得類型編譯為 post-schema-validation 資訊集 (infoset) 之後的值。 這個值指示在執行個體文件中使用 xsi:type 時,如何強制型別。

ContentModel

取得或設定這個複雜型別的編譯後 XmlSchemaContentModel

ContentType

取得包含編譯後值之複雜類型的內容模型。

ContentTypeParticle

取得包含 ContentType 物件編譯後值的物件。

Datatype

取得複雜型別之資料型別的編譯後值。

(繼承來源 XmlSchemaType)
DerivedBy

取得有關此項目如何從其基底型別衍生的編譯後資訊。

(繼承來源 XmlSchemaType)
Final

取得或設定型別衍生的 final 屬性,指出是否允許進一步衍生。

(繼承來源 XmlSchemaType)
FinalResolved

取得 Final 屬性的編譯後值。

(繼承來源 XmlSchemaType)
Id

取得或設定字串 ID。

(繼承來源 XmlSchemaAnnotated)
IsAbstract

取得或設定資訊,決定是否可在執行個體文件中使用 complexType 項目。

IsMixed

取得或設定資訊,決定複雜類型是否具有混合內容模型 (內容中的標記)。

LineNumber

取得或設定 schema 項目參考之檔案中的行號。

(繼承來源 XmlSchemaObject)
LinePosition

取得或設定 schema 項目參考之檔案中的行位置。

(繼承來源 XmlSchemaObject)
Name

取得或設定類型的名稱。

(繼承來源 XmlSchemaType)
Namespaces

取得或設定 XmlSerializerNamespaces,以便與這個結構描述物件一起使用。

(繼承來源 XmlSchemaObject)
Parent

取得或設定這個 XmlSchemaObject 的父項。

(繼承來源 XmlSchemaObject)
Particle

取得或設定複合項型別為其中一個 XmlSchemaGroupRefXmlSchemaChoiceXmlSchemaAllXmlSchemaSequence 類別。

QualifiedName

取得從這個型別的 Name 屬性 (Attribute) 建置之型別的限定名稱 (Qualified Name)。 這是後結構描述編譯屬性。

(繼承來源 XmlSchemaType)
SourceUri

取得或設定載入結構描述之檔案的來源位置。

(繼承來源 XmlSchemaObject)
TypeCode

取得型別的 XmlTypeCode

(繼承來源 XmlSchemaType)
UnhandledAttributes

取得或設定不屬於目前結構描述之目標命名空間的限定屬性 (Attribute)。

(繼承來源 XmlSchemaAnnotated)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於