XmlSchemaAny Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents the World Wide Web Consortium (W3C) any
element.
public ref class XmlSchemaAny : System::Xml::Schema::XmlSchemaParticle
public class XmlSchemaAny : System.Xml.Schema.XmlSchemaParticle
type XmlSchemaAny = class
inherit XmlSchemaParticle
Public Class XmlSchemaAny
Inherits XmlSchemaParticle
- Inheritance
The following example creates the any
element.
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;
class XmlSchemaExamples
{
public:
static void Main()
{
XmlSchema^ schema = gcnew XmlSchema();
// <element name='htmlText'>
XmlSchemaElement^ xeHtmlText = gcnew XmlSchemaElement();
xeHtmlText->Name = "htmlText";
XmlSchemaComplexType^ ct = gcnew XmlSchemaComplexType();
XmlSchemaSequence^ sequence = gcnew XmlSchemaSequence();
// <any namespace='http://www.w3.org/1999/xhtml'
// minOccurs='1' maxOccurs='unbounded'
// processContents='lax'/>
XmlSchemaAny^ any = gcnew XmlSchemaAny();
any->MinOccurs = 1;
any->MaxOccursString = "unbounded";
any->Namespace = "http://www.w3.org/1999/xhtml";
any->ProcessContents = XmlSchemaContentProcessing::Lax;
sequence->Items->Add(any);
ct->Particle = sequence;
xeHtmlText->SchemaType = ct;
schema->Items->Add(xeHtmlText);
XmlSchemaSet^ schemaSet = gcnew XmlSchemaSet();
schemaSet->ValidationEventHandler += gcnew ValidationEventHandler(ValidationCallbackOne);
schemaSet->Add(schema);
schemaSet->Compile();
XmlSchema^ compiledSchema;
for each (XmlSchema^ schema1 in schemaSet->Schemas())
{
compiledSchema = schema1;
}
XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager(gcnew NameTable());
nsmgr->AddNamespace("xs", "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();
return 0;
};
using System;
using System.Xml;
using System.Xml.Schema;
class XMLSchemaExamples
{
public static void Main()
{
XmlSchema schema = new XmlSchema();
// <element name='htmlText'>
XmlSchemaElement xeHtmlText = new XmlSchemaElement();
xeHtmlText.Name = "htmlText";
XmlSchemaComplexType ct = new XmlSchemaComplexType();
XmlSchemaSequence sequence = new XmlSchemaSequence();
// <any namespace='http://www.w3.org/1999/xhtml'
// minOccurs='1' maxOccurs='unbounded'
// processContents='lax'/>
XmlSchemaAny any = new XmlSchemaAny();
any.MinOccurs = 1;
any.MaxOccursString = "unbounded";
any.Namespace = "http://www.w3.org/1999/xhtml";
any.ProcessContents = XmlSchemaContentProcessing.Lax;
sequence.Items.Add(any);
ct.Particle = sequence;
xeHtmlText.SchemaType = ct;
schema.Items.Add(xeHtmlText);
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
schemaSet.Add(schema);
schemaSet.Compile();
XmlSchema compiledSchema = null;
foreach (XmlSchema schema1 in schemaSet.Schemas())
{
compiledSchema = schema1;
}
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);
}
}
Option Explicit On
Option Strict On
Imports System.Xml
Imports System.Xml.Schema
Class XMLSchemaExamples
Public Shared Sub Main()
Dim schema As New XmlSchema()
' <element name='htmlText'>
Dim xeHtmlText As New XmlSchemaElement()
xeHtmlText.Name = "htmlText"
Dim ct As New XmlSchemaComplexType()
Dim sequence As New XmlSchemaSequence()
' <any namespace='http://www.w3.org/1999/xhtml'
' minOccurs='1' maxOccurs='unbounded'
' processContents='lax'/>
Dim any As New XmlSchemaAny()
any.MinOccurs = 1
any.MaxOccursString = "unbounded"
any.Namespace = "http://www.w3.org/1999/xhtml"
any.ProcessContents = XmlSchemaContentProcessing.Lax
sequence.Items.Add(any)
ct.Particle = sequence
xeHtmlText.SchemaType = ct
schema.Items.Add(xeHtmlText)
Dim schemaSet As New XmlSchemaSet()
AddHandler schemaSet.ValidationEventHandler, AddressOf ValidationCallbackOne
schemaSet.Add(schema)
schemaSet.Compile()
Dim compiledSchema As XmlSchema = Nothing
For Each schema1 As XmlSchema In schemaSet.Schemas()
compiledSchema = schema1
Next
Dim nsmgr As New XmlNamespaceManager(New NameTable())
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
compiledSchema.Write(Console.Out, nsmgr)
End Sub
Public Shared Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As ValidationEventArgs)
Console.WriteLine(args.Message)
End Sub
End Class
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='htmlText'>
<xs:complexType>
<xs:sequence>
<xs:any namespace='http://www.w3.org/1999/xhtml'
minOccurs='1' maxOccurs='unbounded'
processContents='lax'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
The any
element enables any element from the specified namespace or namespaces to appear in the containing complexType
element.
Xml |
Initializes a new instance of the XmlSchemaAny class. |
Annotation |
Gets or sets the |
Id |
Gets or sets the string id. (Inherited from XmlSchemaAnnotated) |
Line |
Gets or sets the line number in the file to which the |
Line |
Gets or sets the line position in the file to which the |
Max |
Gets or sets the maximum number of times the particle can occur. (Inherited from XmlSchemaParticle) |
Max |
Gets or sets the number as a string value. Maximum number of times the particle can occur. (Inherited from XmlSchemaParticle) |
Min |
Gets or sets the minimum number of times the particle can occur. (Inherited from XmlSchemaParticle) |
Min |
Gets or sets the number as a string value. The minimum number of times the particle can occur. (Inherited from XmlSchemaParticle) |
Namespace |
Gets or sets the namespaces containing the elements that can be used. |
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) |
Process |
Gets or sets information about how an application or XML processor should handle the validation of XML documents for the elements specified by the |
Source |
Gets or sets the source location for the file that loaded the schema. (Inherited from XmlSchemaObject) |
Unhandled |
Gets or sets the qualified attributes that do not belong to the current schema's target namespace. (Inherited from XmlSchemaAnnotated) |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Product | Versions |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: