XmlSchemaComplexType 类

定义

表示 complexType 由万维网联盟 (W3C) 指定的 XML 架构中的元素。 此类定义一个复杂类型,用于确定元素的属性和内容集。

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

获取此复杂类型及其基类型的所有已遵守属性的集合。

AttributeWildcard

获取此复杂类型及其基类型的编译后值 anyAttribute

BaseSchemaType
已过时.
已过时.
已过时.

获取编译后对象类型或内置的 XML 架构定义语言(XSD)数据类型、simpleType 元素或 complexType 元素。 这是架构编译后信息集属性。

(继承自 XmlSchemaType)
BaseXmlSchemaType

获取此架构类型的基类型的编译后值。

(继承自 XmlSchemaType)
Block

获取或设置 block 属性。

BlockResolved

获取类型编译为后架构验证信息集(infoset)后的值。 此值指示在实例文档中使用时 xsi:type 如何强制执行类型。

ContentModel

获取或设置此复杂类型的编译 XmlSchemaContentModel 后。

ContentType

获取保存编译后值的复杂类型的内容模型。

ContentTypeParticle

获取包含粒子编译后值的 ContentType 粒子。

Datatype

获取复杂类型的数据类型的编译后值。

(继承自 XmlSchemaType)
DerivedBy

获取有关此元素如何从其基类型派生的编译后信息。

(继承自 XmlSchemaType)
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

获取或设置组合器类型作为其中XmlSchemaGroupRef一种、XmlSchemaChoiceXmlSchemaAllXmlSchemaSequence类。

QualifiedName

获取从 Name 此类型的属性生成的类型的限定名称。 这是架构编译后属性。

(继承自 XmlSchemaType)
SourceUri

获取或设置加载架构的文件的源位置。

(继承自 XmlSchemaObject)
TypeCode

XmlTypeCode获取类型。

(继承自 XmlSchemaType)
UnhandledAttributes

获取或设置不属于当前架构的目标命名空间的限定属性。

(继承自 XmlSchemaAnnotated)

方法

名称 说明
Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
ToString()

返回一个表示当前对象的字符串。

(继承自 Object)

适用于