public class XmlSchemaAttributeGroup : XmlSchemaAnnotated
|
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");
schema.Compile(new ValidationEventHandler(ValidationCallbackOne));
XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
schema.Write(Console.Out, nsmgr);
}
public static void ValidationCallbackOne(object sender, ValidationEventArgs args) {
Console.WriteLine(args.Message);
}
}
The following XML file is generated for the preceding code example.
<?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>
| ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. |
| 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. |
| AnyAttribute | Read-write Gets or sets the XmlSchemaAnyAttribute component of the attribute group. |
| Attributes | Read-only Gets the collection of attributes for the attribute group. Contains XmlSchemaAttribute and XmlSchemaAttributeGroupRef elements. |
| 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 | Read-write Gets or sets the name of the attribute group. |
| Namespaces (inherited from System.Xml.Schema.XmlSchemaObject) |
Read-write See base class member description: System.Xml.Schema.XmlSchemaObject.Namespaces |
| RedefinedAttributeGroup | Read-only |
| 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. |
| 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. |
| 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:
public XmlSchemaAttributeGroup(); |
public XmlSchemaAnnotation Annotation {get; set;}
|
public XmlSchemaAnyAttribute AnyAttribute {get; set;}
|
public XmlSchemaObjectCollection Attributes {get;}
|
public string Id {get; set;}
|
Optional.
public int LineNumber {get; set;}
|
public int LinePosition {get; set;}
|
public string Name {get; set;}
|
public XmlSerializerNamespaces Namespaces {get; set;}
|
public XmlSchemaAttributeGroup RedefinedAttributeGroup {get;}
|
public string SourceUri {get; set;}
|
public XmlAttribute[] UnhandledAttributes {get; set;}
|
~XmlSchemaAttributeGroup(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |