XmlSchemaKeyref 클래스

정의

이 클래스는 W3C(World Wide Web 컨소시엄)에서 지정한 대로 XML 스키마의 keyref 요소를 나타냅니다.

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

예제

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

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

using namespace System;
using namespace System::Collections;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Xsl;
using namespace System::Xml::Schema;
public ref class XmlSchemaObjectGenerator
{
private:
    static void ValidationCallback( Object^ /*sender*/, ValidationEventArgs^ args )
    {
        if ( args->Severity == XmlSeverityType::Warning )
            Console::Write( "WARNING: " );
        else
            if ( args->Severity == XmlSeverityType::Error )
                Console::Write( "ERROR: " );

        Console::WriteLine( args->Message );
    }

    // XmlSchemaObjectGenerator
    int main()
    {
        XmlTextReader^ tr = gcnew XmlTextReader( "empty.xsd" );
        XmlSchema^ schema = XmlSchema::Read( tr, gcnew ValidationEventHandler( XmlSchemaObjectGenerator::ValidationCallback ) );
        schema->ElementFormDefault = XmlSchemaForm::Qualified;
        schema->TargetNamespace = "http://www.example.com/Report";
        {
            XmlSchemaElement^ element = gcnew XmlSchemaElement;
            element->Name = "purchaseReport";
            XmlSchemaComplexType^ element_complexType = gcnew XmlSchemaComplexType;
            XmlSchemaSequence^ element_complexType_sequence = gcnew XmlSchemaSequence;
            {
                XmlSchemaElement^ element_complexType_sequence_element = gcnew XmlSchemaElement;
                element_complexType_sequence_element->Name = "region";
                element_complexType_sequence_element->SchemaTypeName = gcnew XmlQualifiedName( "String*","http://www.w3.org/2001/XMLSchema" );
                {
                    XmlSchemaKeyref^ element_complexType_sequence_element_keyref = gcnew XmlSchemaKeyref;
                    element_complexType_sequence_element_keyref->Name = "dummy2";
                    element_complexType_sequence_element_keyref->Selector = gcnew XmlSchemaXPath;
                    element_complexType_sequence_element_keyref->Selector->XPath = "r:zip/r:part";
                    {
                        XmlSchemaXPath^ field = gcnew XmlSchemaXPath;
                        field->XPath = "@number";
                        element_complexType_sequence_element_keyref->Fields->Add( field );
                    }
                    element_complexType_sequence_element_keyref->Refer = gcnew XmlQualifiedName( "pNumKey","http://www.example.com/Report" );
                    element_complexType_sequence_element->Constraints->Add( element_complexType_sequence_element_keyref );
                }
                element_complexType_sequence->Items->Add( element_complexType_sequence_element );
            }
            element_complexType->Particle = element_complexType_sequence;
            {
                XmlSchemaAttribute^ element_complexType_attribute = gcnew XmlSchemaAttribute;
                element_complexType_attribute->Name = "periodEnding";
                element_complexType_attribute->SchemaTypeName = gcnew XmlQualifiedName( "date","http://www.w3.org/2001/XMLSchema" );
                element_complexType->Attributes->Add( element_complexType_attribute );
            }
            element->SchemaType = element_complexType;
            {
                XmlSchemaKey^ element_key = gcnew XmlSchemaKey;
                element_key->Name = "pNumKey";
                element_key->Selector = gcnew XmlSchemaXPath;
                element_key->Selector->XPath = "r:parts/r:part";
                {
                    XmlSchemaXPath^ field = gcnew XmlSchemaXPath;
                    field->XPath = "@number";
                    element_key->Fields->Add( field );
                }
                element->Constraints->Add( element_key );
            }
            schema->Items->Add( element );
        }
        schema->Write( Console::Out );

        return 0;
    } // main
};
using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.Schema;

public class XmlSchemaObjectGenerator {

    private static void ValidationCallback(object sender, ValidationEventArgs args ){

    if(args.Severity == XmlSeverityType.Warning)
        Console.Write("WARNING: ");
    else if(args.Severity == XmlSeverityType.Error)
        Console.Write("ERROR: ");

    Console.WriteLine(args.Message);
    }

    public static void Main() {

      XmlTextReader tr = new XmlTextReader("empty.xsd");
        XmlSchema schema = XmlSchema.Read(tr, new ValidationEventHandler(ValidationCallback));

            schema.ElementFormDefault = XmlSchemaForm.Qualified;

            schema.TargetNamespace = "http://www.example.com/Report";

            {

        XmlSchemaElement element = new XmlSchemaElement();
        element.Name = "purchaseReport";

        XmlSchemaComplexType element_complexType = new XmlSchemaComplexType();

        XmlSchemaSequence element_complexType_sequence = new XmlSchemaSequence();

            {

        XmlSchemaElement element_complexType_sequence_element = new XmlSchemaElement();
        element_complexType_sequence_element.Name = "region";
        element_complexType_sequence_element.SchemaTypeName =
                new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
            ;

            {

        XmlSchemaKeyref element_complexType_sequence_element_keyref = new XmlSchemaKeyref();
        element_complexType_sequence_element_keyref.Name = "dummy2";
        element_complexType_sequence_element_keyref.Selector = new XmlSchemaXPath();
            element_complexType_sequence_element_keyref.Selector.XPath = "r:zip/r:part";

            {
                XmlSchemaXPath field = new XmlSchemaXPath();
                
                field.XPath = "@number";
                element_complexType_sequence_element_keyref.Fields.Add(field);
            }
        element_complexType_sequence_element_keyref.Refer =
                new XmlQualifiedName("pNumKey", "http://www.example.com/Report")
            ;
        element_complexType_sequence_element.Constraints.Add(element_complexType_sequence_element_keyref);
            }
        element_complexType_sequence.Items.Add(element_complexType_sequence_element);
            }
        element_complexType.Particle = element_complexType_sequence;

            {

        XmlSchemaAttribute element_complexType_attribute = new XmlSchemaAttribute();
        element_complexType_attribute.Name = "periodEnding";
        element_complexType_attribute.SchemaTypeName =
                new XmlQualifiedName("date", "http://www.w3.org/2001/XMLSchema")
            ;
        element_complexType.Attributes.Add(element_complexType_attribute);
            }
        element.SchemaType = element_complexType;

            {

        XmlSchemaKey element_key = new XmlSchemaKey();
        element_key.Name = "pNumKey";
        element_key.Selector = new XmlSchemaXPath();
            element_key.Selector.XPath = "r:parts/r:part";

            {
                XmlSchemaXPath field = new XmlSchemaXPath();
                
                field.XPath = "@number";
                element_key.Fields.Add(field);
            }
        element.Constraints.Add(element_key);
            }

                schema.Items.Add(element);
            }

        schema.Write(Console.Out);
    }/* Main() */
}
//XmlSchemaObjectGenerator
Imports System.Collections
Imports System.IO
Imports System.Xml
Imports System.Xml.Xsl
Imports System.Xml.Schema

Public Class XmlSchemaObjectGenerator
   
   Private Shared Sub ValidationCallback(sender As Object, args As ValidationEventArgs)
      
      If args.Severity = XmlSeverityType.Warning Then
         Console.Write("WARNING: ")
      Else
         If args.Severity = XmlSeverityType.Error Then
            Console.Write("ERROR: ")
         End If 
      End If
      Console.WriteLine(args.Message)
   End Sub
   
   
   
   Public Shared Sub Main()
      
      
      Dim tr As New XmlTextReader("empty.xsd")
      Dim schema As XmlSchema = XmlSchema.Read(tr, New ValidationEventHandler(AddressOf ValidationCallback))
      
      schema.ElementFormDefault = XmlSchemaForm.Qualified
      
      schema.TargetNamespace = "http://www.example.com/Report"
      
      If (True) Then
         
         Dim element As New XmlSchemaElement()
         element.Name = "purchaseReport"
         
         Dim element_complexType As New XmlSchemaComplexType()
         
         Dim element_complexType_sequence As New XmlSchemaSequence()
         
         If (True) Then
            
            Dim element_complexType_sequence_element As New XmlSchemaElement()
            element_complexType_sequence_element.Name = "region"
            element_complexType_sequence_element.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
            
            If (True) Then
               
               Dim element_complexType_sequence_element_keyref As New XmlSchemaKeyref()
               element_complexType_sequence_element_keyref.Name = "dummy2"
               element_complexType_sequence_element_keyref.Selector = New XmlSchemaXPath()
               element_complexType_sequence_element_keyref.Selector.XPath = "r:zip/r:part"
               
               If (True) Then
                  Dim field As New XmlSchemaXPath()
                  
                  field.XPath = "@number"
                  element_complexType_sequence_element_keyref.Fields.Add(field)
               End If
               element_complexType_sequence_element_keyref.Refer = New XmlQualifiedName("pNumKey", "http://www.example.com/Report")
               element_complexType_sequence_element.Constraints.Add(element_complexType_sequence_element_keyref)
            End If
            element_complexType_sequence.Items.Add(element_complexType_sequence_element)
         End If
         element_complexType.Particle = element_complexType_sequence
         
         If (True) Then
            
            Dim element_complexType_attribute As New XmlSchemaAttribute()
            element_complexType_attribute.Name = "periodEnding"
            element_complexType_attribute.SchemaTypeName = New XmlQualifiedName("date", "http://www.w3.org/2001/XMLSchema")
            element_complexType.Attributes.Add(element_complexType_attribute)
         End If
         element.SchemaType = element_complexType
         
         If (True) Then
            
            Dim element_key As New XmlSchemaKey()
            element_key.Name = "pNumKey"
            element_key.Selector = New XmlSchemaXPath()
            element_key.Selector.XPath = "r:parts/r:part"
            
            If (True) Then
               Dim field As New XmlSchemaXPath()
               
               field.XPath = "@number"
               element_key.Fields.Add(field)
            End If
            element.Constraints.Add(element_key)
         End If
         
         schema.Items.Add(element)
      End If
      
      schema.Write(Console.Out)
   End Sub
End Class

' Main() 

'XmlSchemaObjectGenerator

다음 XML 파일은 앞의 코드 예제에 대 한 생성 됩니다.

<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:r="http://www.example.com/Report" elementFormDefault="qualified" targetNamespace="http://www.example.com/Report" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="purchaseReport">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="region" type="xs:string">
          <xs:keyref name="dummy2" refer="r:pNumKey">
            <xs:selector xpath="r:zip/r:part" />
            <xs:field xpath="@number" />
          </xs:keyref>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="periodEnding" type="xs:date" />
    </xs:complexType>
    <xs:key name="pNumKey">
      <xs:selector xpath="r:parts/r:part" />
      <xs:field xpath="@number" />
    </xs:key>
  </xs:element>
</xs:schema>

설명

특성 또는 요소 값(또는 값 집합)에 지정된 key 요소 또는 unique 요소와 대응하도록 지정합니다. 제약 조건 이름은 스키마 내에서 고유해야 합니다.

생성자

XmlSchemaKeyref()

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

속성

Annotation

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

(다음에서 상속됨 XmlSchemaAnnotated)
Fields

XPath(XML Path Language) 식 선택기에 대한 자식으로 적용되는 필드의 컬렉션을 가져옵니다.

(다음에서 상속됨 XmlSchemaIdentityConstraint)
Id

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

(다음에서 상속됨 XmlSchemaAnnotated)
LineNumber

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

(다음에서 상속됨 XmlSchemaObject)
LinePosition

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

(다음에서 상속됨 XmlSchemaObject)
Name

identity 제약 조건의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaIdentityConstraint)
Namespaces

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

(다음에서 상속됨 XmlSchemaObject)
Parent

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

(다음에서 상속됨 XmlSchemaObject)
QualifiedName

QualifiedName 속성의 컴파일 이후 값을 보유하는 identity 제약 조건의 정규화된 이름을 가져옵니다.

(다음에서 상속됨 XmlSchemaIdentityConstraint)
Refer

이 제약 조건이 다른 단순 형식이나 복합 형식에서 참조하는 키의 이름을 가져오거나 설정합니다.

Selector

XPath 식의 selector 요소를 가져오거나 설정합니다.

(다음에서 상속됨 XmlSchemaIdentityConstraint)
SourceUri

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

(다음에서 상속됨 XmlSchemaObject)
UnhandledAttributes

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

(다음에서 상속됨 XmlSchemaAnnotated)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

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

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

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

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

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

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

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

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

(다음에서 상속됨 Object)

적용 대상