System.Xml.Schema.XmlSchemaKeyref Class

Assembly: System.Xml.dll
Namespace: System.Xml.Schema
Summary
Identifies a keyref constraint. Represents the World Wide Web Consortium (W3C) keyref element.
C# Syntax:
public class XmlSchemaKeyref : XmlSchemaIdentityConstraint
Remarks
Specifies that an attribute or element value (or set of values) have a correspondence with those of the specified key or unique element. The constraint name must be unique within a schema.
Example
The following example creates a key element.
using System;
using System.Collections;
using System.IO;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.Schema;

public class XmlSchemaObjectGenerator {
  
  

    public 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

    

The following XML file is generated for the preceding code example.

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

    
See also:
System.Xml.Schema Namespace

System.Xml.Schema.XmlSchemaKeyref Member List:

Public Constructors
ctor #1 Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Public Properties
Annotation
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation


Gets or sets the annotation property.
Fields
(inherited from System.Xml.Schema.XmlSchemaIdentityConstraint)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.Fields


Gets the collection of fields that apply as children for the XML Path Language (XPath) expression selector.
Id
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id


Gets or sets the string id.
LineNumber
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber


Gets or sets the line number in the file to which the schema element refers.
LinePosition
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition


Gets or sets the line position in the file to which the schema element refers.
Name
(inherited from System.Xml.Schema.XmlSchemaIdentityConstraint)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.Name


Gets or sets the name of the identity constraint.
Namespaces
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces


QualifiedName
(inherited from System.Xml.Schema.XmlSchemaIdentityConstraint)
Read-only

See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.QualifiedName


Gets the qualified name of the identity constraint which holds the post-compilation value of the QualifiedName property.
Refer Read-write

Gets or sets the name of the key that this constraint refers to in another simple or complex type.
Selector
(inherited from System.Xml.Schema.XmlSchemaIdentityConstraint)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.Selector


Gets or sets the XML Path Language (XPath) expression selector element.
SourceUri
(inherited from System.Xml.Schema.XmlSchemaObject)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri


Gets or sets the source location for the file that loaded the schema.
UnhandledAttributes
(inherited from System.Xml.Schema.XmlSchemaAnnotated)
Read-write

See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes


Gets or sets the qualified attributes that do not belong to the schema target namespace.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
GetHashCode
(inherited from System.Object)
See base class member description: System.Object.GetHashCode

Derived from System.Object, the primary base class for all objects.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Xml.Schema.XmlSchemaKeyref Member Details

ctor #1
Summary:
Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public XmlSchemaKeyref();

Return to top


Property: Annotation (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Annotation

Summary
Gets or sets the annotation property.
C# Syntax:
public XmlSchemaAnnotation Annotation {get; set;}

Return to top


Property: Fields (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.Fields

Summary
Gets the collection of fields that apply as children for the XML Path Language (XPath) expression selector.
C# Syntax:
public XmlSchemaObjectCollection Fields {get;}
Remarks
The collection of fields that apply as children. Each field in the collection specifies the node set under the context element that the identity constraint applies to.

Return to top


Property: Id (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.Id

Summary
Gets or sets the string id.
C# Syntax:
public string Id {get; set;}
Remarks
The id value must be of type ID and be unique within the document containing this element.

Optional.

Return to top


Property: LineNumber (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LineNumber

Summary
Gets or sets the line number in the file to which the schema element refers.
C# Syntax:
public int LineNumber {get; set;}
Remarks
LineNumber is used to store the line number when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: LinePosition (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.LinePosition

Summary
Gets or sets the line position in the file to which the schema element refers.
C# Syntax:
public int LinePosition {get; set;}
Remarks
This is used to store the line position when a schema is read from a file. This is reported through XmlSchemaException for error handling.

Return to top


Property: Name (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.Name

Summary
Gets or sets the name of the identity constraint.
C# Syntax:
public string Name {get; set;}

Return to top


Property: Namespaces (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces

C# Syntax:
public XmlSerializerNamespaces Namespaces {get; set;}

Return to top


Property: QualifiedName (read-only)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.QualifiedName

Summary
Gets the qualified name of the identity constraint which holds the post-compilation value of the QualifiedName property.
C# Syntax:
public XmlQualifiedName QualifiedName {get;}

Return to top


Property: Refer (read-write)
Summary
Gets or sets the name of the key that this constraint refers to in another simple or complex type.
C# Syntax:
public XmlQualifiedName Refer {get; set;}
Remarks
Name of a key or unique element defined in this schema (or another schema indicated by the specified namespace). The Refer value must be a QName. The Refer value can include a namespace prefix.

Return to top


Property: Selector (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaIdentityConstraint.Selector

Summary
Gets or sets the XML Path Language (XPath) expression selector element.
C# Syntax:
public XmlSchemaXPath Selector {get; set;}
Remarks
An XPath expression that is relative to the element being declared. This expression identifies the node set under the context element that the identity constraint applies to.

Return to top


Property: SourceUri (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaObject.SourceUri

Summary
Gets or sets the source location for the file that loaded the schema.
C# Syntax:
public string SourceUri {get; set;}
Remarks
Provides information for exception handling.

Return to top


Property: UnhandledAttributes (read-write)
Inherited
See base class member description: System.Xml.Schema.XmlSchemaAnnotated.UnhandledAttributes

Summary
Gets or sets the qualified attributes that do not belong to the schema target namespace.
C# Syntax:
public XmlAttribute[] UnhandledAttributes {get; set;}

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~XmlSchemaKeyref();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.