XmlSchemaGroup Class
Class that defines groups at the schema level that are referenced from the complex types. Groups a set of element declarations so that they can be incorporated as a group into complex type definitions. Represents the World Wide Web Consortium (W3C) group element.
For a list of all members of this type, see XmlSchemaGroup Members.
System.Object
System.Xml.Schema.XmlSchemaObject
System.Xml.Schema.XmlSchemaAnnotated
System.Xml.Schema.XmlSchemaGroup
[Visual Basic] Public Class XmlSchemaGroup Inherits XmlSchemaAnnotated [C#] public class XmlSchemaGroup : XmlSchemaAnnotated [C++] public __gc class XmlSchemaGroup : public XmlSchemaAnnotated [JScript] public class XmlSchemaGroup extends XmlSchemaAnnotated
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Example
[Visual Basic, C#, C++] The following example shows the use of the XmlSchemaGroup class.
[Visual Basic] Option Explicit Option Strict Imports System Imports System.Xml Imports System.Xml.Schema Class XMLSchemaExamples Public Shared Sub Main() Dim schema As New XmlSchema() ' <xs:element name="thing1" type="xs:string"/> Dim elementThing1 As New XmlSchemaElement() schema.Items.Add(elementThing1) elementThing1.Name = "thing1" elementThing1.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema") ' <xs:element name="thing2" type="xs:string"/> Dim elementThing2 As New XmlSchemaElement() schema.Items.Add(elementThing2) elementThing2.Name = "thing2" elementThing2.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema") ' <xs:element name="thing3" type="xs:string"/> Dim elementThing3 As New XmlSchemaElement() schema.Items.Add(elementThing3) elementThing3.Name = "thing3" elementThing3.SchemaTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema") ' <xs:attribute name="myAttribute" type="xs:decimal"/> Dim myAttribute As New XmlSchemaAttribute() schema.Items.Add(myAttribute) myAttribute.Name = "myAttribute" myAttribute.SchemaTypeName = New XmlQualifiedName("decimal", "http://www.w3.org/2001/XMLSchema") ' <xs:group name="myGroupOfThings"> Dim myGroupOfThings As New XmlSchemaGroup() schema.Items.Add(myGroupOfThings) myGroupOfThings.Name = "myGroupOfThings" ' <xs:sequence> Dim sequence As New XmlSchemaSequence() myGroupOfThings.Particle = sequence ' <xs:element ref="thing1"/> Dim elementThing1Ref As New XmlSchemaElement() sequence.Items.Add(elementThing1Ref) elementThing1Ref.RefName = New XmlQualifiedName("thing1") ' <xs:element ref="thing2"/> Dim elementThing2Ref As New XmlSchemaElement() sequence.Items.Add(elementThing2Ref) elementThing2Ref.RefName = New XmlQualifiedName("thing2") ' <xs:element ref="thing3"/> Dim elementThing3Ref As New XmlSchemaElement() sequence.Items.Add(elementThing3Ref) elementThing3Ref.RefName = New XmlQualifiedName("thing3") ' <xs:complexType name="myComplexType"> Dim myComplexType As New XmlSchemaComplexType() schema.Items.Add(myComplexType) myComplexType.Name = "myComplexType" ' <xs:group ref="myGroupOfThings"/> Dim myGroupOfThingsRef As New XmlSchemaGroupRef() myComplexType.Particle = myGroupOfThingsRef myGroupOfThingsRef.RefName = New XmlQualifiedName("myGroupOfThings") ' <xs:attribute ref="myAttribute"/> Dim myAttributeRef As New XmlSchemaAttribute() myComplexType.Attributes.Add(myAttributeRef) myAttributeRef.RefName = New XmlQualifiedName("myAttribute") schema.Compile(AddressOf ValidationCallbackOne) Dim nsmgr As New XmlNamespaceManager(New NameTable()) nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema") schema.Write(Console.Out, nsmgr) End Sub 'Main Public Shared Sub ValidationCallbackOne(sender As Object, args As ValidationEventArgs) Console.WriteLine(args.Message) End Sub 'ValidationCallbackOne End Class 'XMLSchemaExamples [C#] using System; using System.Xml; using System.Xml.Schema; class XMLSchemaExamples { public static void Main() { XmlSchema schema = new XmlSchema(); // <xs:element name="thing1" type="xs:string"/> XmlSchemaElement elementThing1 = new XmlSchemaElement(); schema.Items.Add(elementThing1); elementThing1.Name = "thing1"; elementThing1.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="thing2" type="xs:string"/> XmlSchemaElement elementThing2 = new XmlSchemaElement(); schema.Items.Add(elementThing2); elementThing2.Name = "thing2"; elementThing2.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:element name="thing3" type="xs:string"/> XmlSchemaElement elementThing3 = new XmlSchemaElement(); schema.Items.Add(elementThing3); elementThing3.Name = "thing3"; elementThing3.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"); // <xs:attribute name="myAttribute" type="xs:decimal"/> XmlSchemaAttribute myAttribute = new XmlSchemaAttribute(); schema.Items.Add(myAttribute); myAttribute.Name = "myAttribute"; myAttribute.SchemaTypeName = new XmlQualifiedName("decimal", "http://www.w3.org/2001/XMLSchema"); // <xs:group name="myGroupOfThings"> XmlSchemaGroup myGroupOfThings = new XmlSchemaGroup(); schema.Items.Add(myGroupOfThings); myGroupOfThings.Name = "myGroupOfThings"; // <xs:sequence> XmlSchemaSequence sequence = new XmlSchemaSequence(); myGroupOfThings.Particle = sequence; // <xs:element ref="thing1"/> XmlSchemaElement elementThing1Ref = new XmlSchemaElement(); sequence.Items.Add(elementThing1Ref); elementThing1Ref.RefName = new XmlQualifiedName("thing1"); // <xs:element ref="thing2"/> XmlSchemaElement elementThing2Ref = new XmlSchemaElement(); sequence.Items.Add(elementThing2Ref); elementThing2Ref.RefName = new XmlQualifiedName("thing2"); // <xs:element ref="thing3"/> XmlSchemaElement elementThing3Ref = new XmlSchemaElement(); sequence.Items.Add(elementThing3Ref); elementThing3Ref.RefName = new XmlQualifiedName("thing3"); // <xs:complexType name="myComplexType"> XmlSchemaComplexType myComplexType = new XmlSchemaComplexType(); schema.Items.Add(myComplexType); myComplexType.Name = "myComplexType"; // <xs:group ref="myGroupOfThings"/> XmlSchemaGroupRef myGroupOfThingsRef = new XmlSchemaGroupRef(); myComplexType.Particle = myGroupOfThingsRef; myGroupOfThingsRef.RefName = new XmlQualifiedName("myGroupOfThings"); // <xs:attribute ref="myAttribute"/> XmlSchemaAttribute myAttributeRef = new XmlSchemaAttribute(); myComplexType.Attributes.Add(myAttributeRef); myAttributeRef.RefName = new XmlQualifiedName("myAttribute"); 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); } } [C++] #using <mscorlib.dll> #using <System.Xml.dll> using namespace System; using namespace System::Xml; using namespace System::Xml::Schema; __gc class XMLSchemaExamples { public: static void main() { XmlSchema* schema = new XmlSchema(); // <xs:element name="thing1" type="xs:string"/> XmlSchemaElement* elementThing1 = new XmlSchemaElement(); schema->Items->Add(elementThing1); elementThing1->Name = S"thing1"; elementThing1->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema"); // <xs:element name="thing2" type="xs:string"/> XmlSchemaElement* elementThing2 = new XmlSchemaElement(); schema->Items->Add(elementThing2); elementThing2->Name = S"thing2"; elementThing2->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema"); // <xs:element name="thing3" type="xs:string"/> XmlSchemaElement* elementThing3 = new XmlSchemaElement(); schema->Items->Add(elementThing3); elementThing3->Name = S"thing3"; elementThing3->SchemaTypeName = new XmlQualifiedName(S"string", S"http://www.w3.org/2001/XMLSchema"); // <xs:attribute name="myAttribute" type="xs:decimal"/> XmlSchemaAttribute* myAttribute = new XmlSchemaAttribute(); schema->Items->Add(myAttribute); myAttribute->Name = S"myAttribute"; myAttribute->SchemaTypeName = new XmlQualifiedName(S"decimal", S"http://www.w3.org/2001/XMLSchema"); // <xs:group name="myGroupOfThings"> XmlSchemaGroup* myGroupOfThings = new XmlSchemaGroup(); schema->Items->Add(myGroupOfThings); myGroupOfThings->Name = S"myGroupOfThings"; // <xs:sequence> XmlSchemaSequence* sequence = new XmlSchemaSequence(); myGroupOfThings->Particle = sequence; // <xs:element ref="thing1"/> XmlSchemaElement* elementThing1Ref = new XmlSchemaElement(); sequence->Items->Add(elementThing1Ref); elementThing1Ref->RefName = new XmlQualifiedName(S"thing1"); // <xs:element ref="thing2"/> XmlSchemaElement* elementThing2Ref = new XmlSchemaElement(); sequence->Items->Add(elementThing2Ref); elementThing2Ref->RefName = new XmlQualifiedName(S"thing2"); // <xs:element ref="thing3"/> XmlSchemaElement* elementThing3Ref = new XmlSchemaElement(); sequence->Items->Add(elementThing3Ref); elementThing3Ref->RefName = new XmlQualifiedName(S"thing3"); // <xs:complexType name="myComplexType"> XmlSchemaComplexType* myComplexType = new XmlSchemaComplexType(); schema->Items->Add(myComplexType); myComplexType->Name = S"myComplexType"; // <xs:group ref="myGroupOfThings"/> XmlSchemaGroupRef* myGroupOfThingsRef = new XmlSchemaGroupRef(); myComplexType->Particle = myGroupOfThingsRef; myGroupOfThingsRef->RefName = new XmlQualifiedName(S"myGroupOfThings"); // <xs:attribute ref="myAttribute"/> XmlSchemaAttribute* myAttributeRef = new XmlSchemaAttribute(); myComplexType->Attributes->Add(myAttributeRef); myAttributeRef->RefName = new XmlQualifiedName(S"myAttribute"); schema->Compile(new ValidationEventHandler(0, ValidationCallbackOne)); XmlNamespaceManager* nsmgr = new XmlNamespaceManager(new NameTable()); nsmgr->AddNamespace(S"xs", S"http://www.w3.org/2001/XMLSchema"); schema->Write(Console::Out,nsmgr); } static void ValidationCallbackOne(Object* /*sender*/, ValidationEventArgs* args) { Console::WriteLine(args->Message); } }; int main() { XMLSchemaExamples::main(); }
[Visual Basic, C#, C++] 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:element name="thing1" type="xs:string"/>
<xs:element name="thing2" type="xs:string"/>
<xs:element name="thing3" type="xs:string"/>
<xs:attribute name="myAttribute" type="xs:decimal"/>
<xs:group name="myGroupOfThings">
<xs:sequence>
<xs:element ref="thing1"/>
<xs:element ref="thing2"/>
<xs:element ref="thing3"/>
</xs:sequence>
</xs:group>
<xs:complexType name="myComplexType">
<xs:group ref="myGroupOfThings"/>
<xs:attribute ref="myAttribute"/>
</xs:complexType>
</xs:schema>
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Namespace: System.Xml.Schema
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: System.Xml (in System.Xml.dll)