Share via


XmlSchemaAny Classe

Definizione

Rappresenta l'elemento any del World Wide Web Consortium (W3C).

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
Ereditarietà

Esempio

Nell'esempio seguente viene creato l'elemento any .

#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

Il file XML seguente viene generato per l'esempio di codice precedente.


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

Commenti

L'elemento any consente a qualsiasi elemento dello spazio dei nomi o degli spazi dei nomi specificati di essere visualizzati nell'elemento contenente complexType .

Costruttori

XmlSchemaAny()

Inizializza una nuova istanza della classe XmlSchemaAny.

Proprietà

Annotation

Ottiene o imposta la proprietà annotation.

(Ereditato da XmlSchemaAnnotated)
Id

Ottiene o imposta l'ID di stringa.

(Ereditato da XmlSchemaAnnotated)
LineNumber

Ottiene o imposta il numero di riga nel file a cui l'elemento schema fa riferimento.

(Ereditato da XmlSchemaObject)
LinePosition

Ottiene o imposta la posizione di riga nel file a cui l'elemento schema fa riferimento.

(Ereditato da XmlSchemaObject)
MaxOccurs

Ottiene o imposta il numero massimo delle occorrenze possibili di una particella.

(Ereditato da XmlSchemaParticle)
MaxOccursString

Ottiene o imposta il numero come valore stringa. Numero massimo delle occorrenze possibili della particella.

(Ereditato da XmlSchemaParticle)
MinOccurs

Ottiene o imposta il numero minimo delle occorrenze possibili della particella.

(Ereditato da XmlSchemaParticle)
MinOccursString

Ottiene o imposta il numero come valore stringa. Numero minimo delle occorrenze possibili della particella.

(Ereditato da XmlSchemaParticle)
Namespace

Ottiene o imposta gli spazi dei nomi che contengono gli elementi che è possibile utilizzare.

Namespaces

Ottiene o imposta l'oggetto XmlSerializerNamespaces da utilizzare con questo oggetto schema.

(Ereditato da XmlSchemaObject)
Parent

Ottiene o imposta la classe padre della classe XmlSchemaObject.

(Ereditato da XmlSchemaObject)
ProcessContents

Ottiene o imposta informazioni relative a come deve essere gestita la convalida di documenti XML per gli elementi specificati dall'elemento any da una applicazione o da un processore XML.

SourceUri

Ottiene o imposta la posizione di origine per il file che ha caricato lo schema.

(Ereditato da XmlSchemaObject)
UnhandledAttributes

Ottiene o imposta gli attributi qualificati che non appartengono allo spazio dei nomi di destinazione dello schema corrente.

(Ereditato da XmlSchemaAnnotated)

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a