XmlSchemaAttribute 클래스

정의

attribute W3C(World Wide Web 컨소시엄)에서 지정한 XML 스키마의 요소를 나타냅니다. 특성은 다른 문서 요소에 대한 추가 정보를 제공합니다. 특성 태그는 스키마에 대한 문서 요소의 태그 사이에 중첩됩니다. XML 문서에는 요소의 여는 태그에 명명된 항목으로 특성이 표시됩니다.

public ref class XmlSchemaAttribute : System::Xml::Schema::XmlSchemaAnnotated
public class XmlSchemaAttribute : System.Xml.Schema.XmlSchemaAnnotated
type XmlSchemaAttribute = class
    inherit XmlSchemaAnnotated
Public Class XmlSchemaAttribute
Inherits XmlSchemaAnnotated
상속

예제

다음 예제에서는 요소를 만듭니다 attribute .

using System;
using System.Xml;
using System.Xml.Schema;

class XMLSchemaExamples
{
    public static void Main()
    {

        XmlSchema schema = new XmlSchema();

        // <xs:attribute name="mybaseattribute">
        XmlSchemaAttribute attributeBase = new XmlSchemaAttribute();
        schema.Items.Add(attributeBase);
        attributeBase.Name = "mybaseattribute";

        // <xs:simpleType>
        XmlSchemaSimpleType simpleType = new XmlSchemaSimpleType();
        attributeBase.SchemaType = simpleType;

        // <xs:restriction base="integer">
        XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
        simpleType.Content = restriction;
        restriction.BaseTypeName = new XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema");

        // <xs:maxInclusive value="1000"/>
        XmlSchemaMaxInclusiveFacet maxInclusive = new XmlSchemaMaxInclusiveFacet();
        restriction.Facets.Add(maxInclusive);
        maxInclusive.Value = "1000";

        // <xs:complexType name="myComplexType">
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();
        schema.Items.Add(complexType);
        complexType.Name = "myComplexType";

        // <xs:attribute ref="mybaseattribute"/>
        XmlSchemaAttribute attributeBaseRef = new XmlSchemaAttribute();
        complexType.Attributes.Add(attributeBaseRef);
        attributeBaseRef.RefName = new XmlQualifiedName("mybaseattribute");

        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 Explicit On
Option Strict On

Imports System.Xml
Imports System.Xml.Schema

Class XMLSchemaExamples
    Public Shared Sub Main()
        Dim schema As New XmlSchema()

        ' <xs:attribute name="mybaseattribute">
        Dim attributeBase As New XmlSchemaAttribute()
        schema.Items.Add(attributeBase)
        attributeBase.Name = "mybaseattribute"

        ' <xs:simpleType>
        Dim simpleType As New XmlSchemaSimpleType()
        attributeBase.SchemaType = simpleType

        ' <xs:restriction base="integer">
        Dim restriction As New XmlSchemaSimpleTypeRestriction()
        simpleType.Content = restriction
        restriction.BaseTypeName = New XmlQualifiedName("integer", "http://www.w3.org/2001/XMLSchema")

        ' <xs:maxInclusive value="1000"/>
        Dim maxInclusive As New XmlSchemaMaxInclusiveFacet()
        restriction.Facets.Add(maxInclusive)
        maxInclusive.Value = "1000"

        ' <xs:complexType name="myComplexType">
        Dim complexType As New XmlSchemaComplexType()
        schema.Items.Add(complexType)
        complexType.Name = "myComplexType"

        ' <xs:attribute ref="mybaseattribute"/>
        Dim attributeBaseRef As New XmlSchemaAttribute()
        complexType.Attributes.Add(attributeBaseRef)
        attributeBaseRef.RefName = New XmlQualifiedName("mybaseattribute")

        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:attribute name="mybaseattribute">
        <xs:simpleType>
            <xs:restriction base="xs:integer">
                <xs:maxInclusive value="1000" />
            </xs:restriction>
        </xs:simpleType>
    </xs:attribute>
    <xs:complexType name="myComplexType">
        <xs:attribute ref="mybaseattribute" />
    </xs:complexType>
</xs:schema>

설명

특성 선언은 요소의 schema 자식 요소(전역 범위 포함) 또는 복합 형식 정의 내에 있을 수 있습니다. 복합 형식의 경우 특성 선언은 전역 범위가 있는 특성에 대한 로컬 선언 또는 참조로 표시될 수 있습니다. 전역 및 로컬 특성 선언에는 모두 기존 단순 형식을 참조하는 선택적 형식 특성이 있습니다. 선택적 형식 특성을 사용하지 않는 경우 특성 선언(전역 또는 로컬)은 로컬 단순 형식을 정의해야 합니다.

생성자

Name Description
XmlSchemaAttribute()

XmlSchemaAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

Name Description
Annotation

속성을 가져오거나 설정합니다 annotation .

(다음에서 상속됨 XmlSchemaAnnotated)
AttributeSchemaType

XmlSchemaSimpleType 특성 또는 SchemaTypeName 특성의 형식을 나타내는 SchemaType 개체를 가져옵니다.

AttributeType
사용되지 않음.
사용되지 않음.

속성의 컴파일 후 값을 보유하는 특성 또는 SchemaType 특성에 SchemaTypeName 따라 CLR(공용 언어 런타임) 개체를 AttributeType 가져옵니다.

DefaultValue

특성의 기본값을 가져오거나 설정합니다.

FixedValue

특성의 고정 값을 가져오거나 설정합니다.

Form

특성의 폼을 가져오거나 설정합니다.

Id

문자열 ID를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaAnnotated)
LineNumber

요소가 참조하는 schema 파일의 줄 번호를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
LinePosition

요소가 참조하는 schema 파일의 줄 위치를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
Name

특성의 이름을 가져오거나 설정합니다.

Namespaces

이 스키마 개체에 사용할 개체를 가져오거나 설정합니다 XmlSerializerNamespaces .

(다음에서 상속됨 XmlSchemaObject)
Parent

XmlSchemaObject항목의 부모를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
QualifiedName

특성의 정규화된 이름을 가져옵니다.

RefName

이 스키마에 선언된 특성의 이름(또는 지정된 네임스페이스가 나타내는 다른 스키마)을 가져오거나 설정합니다.

SchemaType

특성 형식을 단순 형식으로 가져오거나 설정합니다.

SchemaTypeName

이 스키마에 정의된 단순 형식(또는 지정된 네임스페이스가 나타내는 다른 스키마)의 이름을 가져오거나 설정합니다.

SourceUri

스키마를 로드한 파일의 원본 위치를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaObject)
UnhandledAttributes

현재 스키마의 대상 네임스페이스에 속하지 않는 정규화된 특성을 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaAnnotated)
Use

특성이 사용되는 방법에 대한 정보를 가져오거나 설정합니다.

메서드

Name Description
Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상