XmlSchemaAttributeGroup 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表 attributeGroup 由萬維網聯盟(W3C)規定的 XML 架構中的元素。 AttributesGroups 提供一種機制,將一組屬性宣告分組,使其能作為群組整合進複雜的型別定義中。
public ref class XmlSchemaAttributeGroup : System::Xml::Schema::XmlSchemaAnnotated
public class XmlSchemaAttributeGroup : System.Xml.Schema.XmlSchemaAnnotated
type XmlSchemaAttributeGroup = class
inherit XmlSchemaAnnotated
Public Class XmlSchemaAttributeGroup
Inherits XmlSchemaAnnotated
- 繼承
範例
以下範例會產生該 attributeGroup 元素。
using System;
using System.Xml;
using System.Xml.Schema;
class XMLSchemaExamples
{
public static void Main()
{
XmlSchema schema = new XmlSchema();
// <xs:attributeGroup name="myAttributeGroup">
XmlSchemaAttributeGroup myAttributeGroup = new XmlSchemaAttributeGroup();
schema.Items.Add(myAttributeGroup);
myAttributeGroup.Name = "myAttributeGroup";
// <xs:attribute name="someattribute1" type="xs:integer"/>
XmlSchemaAttribute someattribute1 = new XmlSchemaAttribute();
myAttributeGroup.Attributes.Add(someattribute1);
someattribute1.Name = "someattribute1";
someattribute1.SchemaTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");
// <xs:attribute name="someattribute2" type="xs:string"/>
XmlSchemaAttribute someattribute2 = new XmlSchemaAttribute();
myAttributeGroup.Attributes.Add(someattribute2);
someattribute2.Name = "someattribute2";
someattribute2.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:complexType name="myElementType">
XmlSchemaComplexType myElementType = new XmlSchemaComplexType();
schema.Items.Add(myElementType);
myElementType.Name = "myElementType";
// <xs:attributeGroup ref="myAttributeGroup"/>
XmlSchemaAttributeGroupRef myAttributeGroupRef = new XmlSchemaAttributeGroupRef();
myElementType.Attributes.Add(myAttributeGroupRef);
myAttributeGroupRef.RefName = new XmlQualifiedName("myAttributeGroup");
// <xs:attributeGroup name="myAttributeGroupA">
XmlSchemaAttributeGroup myAttributeGroupA = new XmlSchemaAttributeGroup();
schema.Items.Add(myAttributeGroupA);
myAttributeGroupA.Name = "myAttributeGroupA";
// <xs:attribute name="someattribute10" type="xs:integer"/>
XmlSchemaAttribute someattribute10 = new XmlSchemaAttribute();
myAttributeGroupA.Attributes.Add(someattribute10);
someattribute10.Name = "someattribute10";
someattribute10.SchemaTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");
// <xs:attribute name="someattribute11" type="xs:string"/>
XmlSchemaAttribute someattribute11 = new XmlSchemaAttribute();
myAttributeGroupA.Attributes.Add(someattribute11);
someattribute11.Name = "someattribute11";
someattribute11.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <xs:attributeGroup name="myAttributeGroupB">
XmlSchemaAttributeGroup myAttributeGroupB = new XmlSchemaAttributeGroup();
schema.Items.Add(myAttributeGroupB);
myAttributeGroupB.Name = "myAttributeGroupB";
// <xs:attribute name="someattribute20" type="xs:date"/>
XmlSchemaAttribute someattribute20 = new XmlSchemaAttribute();
myAttributeGroupB.Attributes.Add(someattribute20);
someattribute20.Name = "someattribute20";
someattribute20.SchemaTypeName = new XmlQualifiedName("date", "http://www.w3.org/2001/XMLSchema");
// <xs:attributeGroup ref="myAttributeGroupA"/>
XmlSchemaAttributeGroupRef myAttributeGroupRefA = new XmlSchemaAttributeGroupRef();
myAttributeGroupB.Attributes.Add(myAttributeGroupRefA);
myAttributeGroupRefA.RefName = new XmlQualifiedName("myAttributeGroupA");
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);
}
}
Option Strict On
Option Explicit On
Imports System.Xml
Imports System.Xml.Schema
Class XMLSchemaExamples
Public Shared Sub Main()
Dim schema As New XmlSchema()
' <xs:attributeGroup name="myAttributeGroup">
Dim myAttributeGroup As New XmlSchemaAttributeGroup()
schema.Items.Add(myAttributeGroup)
myAttributeGroup.Name = "myAttributeGroup"
' <xs:attribute name="someattribute1" type="xs:integer"/>
Dim someattribute1 As New XmlSchemaAttribute()
myAttributeGroup.Attributes.Add(someattribute1)
someattribute1.Name = "someattribute1"
someattribute1.SchemaTypeName = New XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema")
' <xs:attribute name="someattribute2" type="xs:string"/>
Dim someattribute2 As New XmlSchemaAttribute()
myAttributeGroup.Attributes.Add(someattribute2)
someattribute2.Name = "someattribute2"
someattribute2.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
' <xs:complexType name="myElementType">
Dim myElementType As New XmlSchemaComplexType()
schema.Items.Add(myElementType)
myElementType.Name = "myElementType"
' <xs:attributeGroup ref="myAttributeGroup"/>
Dim myAttributeGroupRef As New XmlSchemaAttributeGroupRef()
myElementType.Attributes.Add(myAttributeGroupRef)
myAttributeGroupRef.RefName = New XmlQualifiedName("myAttributeGroup")
' <xs:attributeGroup name="myAttributeGroupA">
Dim myAttributeGroupA As New XmlSchemaAttributeGroup()
schema.Items.Add(myAttributeGroupA)
myAttributeGroupA.Name = "myAttributeGroupA"
' <xs:attribute name="someattribute10" type="xs:integer"/>
Dim someattribute10 As New XmlSchemaAttribute()
myAttributeGroupA.Attributes.Add(someattribute10)
someattribute10.Name = "someattribute10"
someattribute10.SchemaTypeName = New XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema")
' <xs:attribute name="someattribute11" type="xs:string"/>
Dim someattribute11 As New XmlSchemaAttribute()
myAttributeGroupA.Attributes.Add(someattribute11)
someattribute11.Name = "someattribute11"
someattribute11.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
' <xs:attributeGroup name="myAttributeGroupB">
Dim myAttributeGroupB As New XmlSchemaAttributeGroup()
schema.Items.Add(myAttributeGroupB)
myAttributeGroupB.Name = "myAttributeGroupB"
' <xs:attribute name="someattribute20" type="xs:date"/>
Dim someattribute20 As New XmlSchemaAttribute()
myAttributeGroupB.Attributes.Add(someattribute20)
someattribute20.Name = "someattribute20"
someattribute20.SchemaTypeName = New XmlQualifiedName("date", "http://www.w3.org/2001/XMLSchema")
' <xs:attributeGroup ref="myAttributeGroupA"/>
Dim myAttributeGroupRefA As New XmlSchemaAttributeGroupRef()
myAttributeGroupB.Attributes.Add(myAttributeGroupRefA)
myAttributeGroupRefA.RefName = New XmlQualifiedName("myAttributeGroupA")
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:attributeGroup name="myAttributeGroup">
<xs:attribute name="someattribute1" type="xs:integer"/>
<xs:attribute name="someattribute2" type="xs:string"/>
</xs:attributeGroup>
<xs:complexType name="myElementType">
<xs:attributeGroup ref="myAttributeGroup"/>
</xs:complexType>
<xs:attributeGroup name="myAttributeGroupA">
<xs:attribute name="someattribute10" type="xs:integer"/>
<xs:attribute name="someattribute11" type="xs:string"/>
</xs:attributeGroup>
<xs:attributeGroup name="myAttributeGroupB">
<xs:attribute name="someattribute20" type="xs:date"/>
<xs:attributeGroup ref="myAttributeGroupA"/>
</xs:attributeGroup>
</xs:schema>
備註
屬性群只能定義為該 schema 元素的子節點。 此時, name 屬性必須存在,且包含 attribute構成屬性群的 、 attributeGroup或 anyAttribute 元素。 當某 complexType 個或元素 attributeGroup 包含屬性群組時, ref 該屬性必須存在,且不允許該 name 屬性。
建構函式
| 名稱 | Description |
|---|---|
| XmlSchemaAttributeGroup() |
初始化 XmlSchemaAttributeGroup 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Annotation |
取得或設定該 |
| AnyAttribute |
取得或設定 XmlSchemaAnyAttribute 屬性群組的組件。 |
| Attributes |
取得屬性群組的屬性集合。 包含 |
| Id |
取得或設定字串 ID。 (繼承來源 XmlSchemaAnnotated) |
| LineNumber |
取得或設定該 |
| LinePosition |
取得或設定該元素所指檔案 |
| Name |
取得或設定屬性群組名稱。 |
| Namespaces |
用這個結構物件取得或設定 XmlSerializerNamespaces 使用 。 (繼承來源 XmlSchemaObject) |
| Parent |
取得或設定此 XmlSchemaObject的父節點。 (繼承來源 XmlSchemaObject) |
| QualifiedName |
會取得屬性群組的限定名稱。 |
| RedefinedAttributeGroup |
從 XML 架構取得重新定義的屬性群組屬性。 |
| SourceUri |
取得或設定載入結構檔案的來源位置。 (繼承來源 XmlSchemaObject) |
| UnhandledAttributes |
取得或設定不屬於目前結構目標命名空間的限定屬性。 (繼承來源 XmlSchemaAnnotated) |
方法
| 名稱 | Description |
|---|---|
| Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
| GetHashCode() |
做為預設哈希函式。 (繼承來源 Object) |
| GetType() |
取得目前實例的 Type。 (繼承來源 Object) |
| MemberwiseClone() |
建立目前 Object的淺層複本。 (繼承來源 Object) |
| ToString() |
傳回表示目前 物件的字串。 (繼承來源 Object) |