XmlSchemaKeyref Class
This class represents the keyref element from XMLSchema as specified by the .
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaIdentityConstraint
System.Xml.Schema.XmlSchemaKeyref
Assembly: System.Xml (in System.Xml.dll)
The XmlSchemaKeyref type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | Annotation | Gets or sets the annotation property. (Inherited from XmlSchemaAnnotated.) |
![]() ![]() | Fields | Gets the collection of fields that apply as children for the XML Path Language (XPath) expression selector. (Inherited from XmlSchemaIdentityConstraint.) |
![]() ![]() | Id | Gets or sets the string id. (Inherited from XmlSchemaAnnotated.) |
![]() ![]() | LineNumber | Gets or sets the line number in the file to which the schema element refers. (Inherited from XmlSchemaObject.) |
![]() ![]() | LinePosition | Gets or sets the line position in the file to which the schema element refers. (Inherited from XmlSchemaObject.) |
![]() ![]() | Name | Gets or sets the name of the identity constraint. (Inherited from XmlSchemaIdentityConstraint.) |
![]() ![]() | Namespaces | Gets or sets the XmlSerializerNamespaces to use with this schema object. (Inherited from XmlSchemaObject.) |
![]() ![]() | Parent | Gets or sets the parent of this XmlSchemaObject. (Inherited from XmlSchemaObject.) |
![]() ![]() | QualifiedName | Gets the qualified name of the identity constraint, which holds the post-compilation value of the QualifiedName property. (Inherited from XmlSchemaIdentityConstraint.) |
![]() ![]() | Refer | Gets or sets the name of the key that this constraint refers to in another simple or complex type. |
![]() ![]() | Selector | Gets or sets the XPath expression selector element. (Inherited from XmlSchemaIdentityConstraint.) |
![]() ![]() | SourceUri | Gets or sets the source location for the file that loaded the schema. (Inherited from XmlSchemaObject.) |
![]() ![]() | UnhandledAttributes | Gets or sets the qualified attributes that do not belong to the current schema's target namespace. (Inherited from XmlSchemaAnnotated.) |
| Name | Description | |
|---|---|---|
![]() ![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() ![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() ![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() ![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() ![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() ![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
The following example creates a key element.
Imports System 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 'ValidationCallback 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 'Main End Class 'XmlSchemaObjectGenerator ' 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>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.



