XmlSchemaAnyAttribute Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Représente l’élément W3C (World Wide Web Consortium). anyAttribute
public ref class XmlSchemaAnyAttribute : System::Xml::Schema::XmlSchemaAnnotated
public class XmlSchemaAnyAttribute : System.Xml.Schema.XmlSchemaAnnotated
type XmlSchemaAnyAttribute = class
inherit XmlSchemaAnnotated
Public Class XmlSchemaAnyAttribute
Inherits XmlSchemaAnnotated
- Héritage
Exemples
L’exemple suivant crée l’élément anyAttribute .
using System;
using System.Xml;
using System.Xml.Schema;
class XMLSchemaExamples
{
public static void Main()
{
XmlSchema schema = new XmlSchema();
// <element name="stringElementWithAnyAttribute">
XmlSchemaElement element = new XmlSchemaElement();
schema.Items.Add(element);
element.Name = "stringElementWithAnyAttribute";
XmlSchemaComplexType complexType = new XmlSchemaComplexType();
element.SchemaType = complexType;
XmlSchemaSimpleContent simpleContent = new XmlSchemaSimpleContent();
complexType.ContentModel = simpleContent;
// <extension base="xs:string">
XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
simpleContent.Content = extension;
extension.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
// <anyAttribute namespace="##targetNamespace"/>
XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
extension.AnyAttribute = anyAttribute;
anyAttribute.Namespace = "##targetNamespace";
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");
compiledSchema.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="stringElementWithAnyAttribute">
Dim element As New XmlSchemaElement()
schema.Items.Add(element)
element.Name = "stringElementWithAnyAttribute"
Dim complexType As New XmlSchemaComplexType()
element.SchemaType = complexType
Dim simpleContent As New XmlSchemaSimpleContent()
complexType.ContentModel = simpleContent
' <extension base="xs:string">
Dim extension As New XmlSchemaSimpleContentExtension()
simpleContent.Content = extension
extension.BaseTypeName = New XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
' <anyAttribute namespace="##targetNamespace"/>
Dim anyAttribute As New XmlSchemaAnyAttribute()
extension.AnyAttribute = anyAttribute
anyAttribute.Namespace = "##targetNamespace"
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
Le fichier XML suivant est généré pour l’exemple de code précédent.
<?xml version="1.0" encoding="IBM437"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="stringElementWithAnyAttribute">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:anyAttribute namespace="##targetNamespace"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:schema>
Remarques
L’élément anyAttribute permet à n’importe quel attribut de l’espace de noms ou des espaces de noms spécifiés d’apparaître dans l’élément conteneur complexType .
Constructeurs
| Nom | Description |
|---|---|
| XmlSchemaAnyAttribute() |
Initialise une nouvelle instance de la classe XmlSchemaAnyAttribute. |
Propriétés
| Nom | Description |
|---|---|
| Annotation |
Obtient ou définit la |
| Id |
Obtient ou définit l’ID de chaîne. (Hérité de XmlSchemaAnnotated) |
| LineNumber |
Obtient ou définit le numéro de ligne dans le fichier auquel l’élément |
| LinePosition |
Obtient ou définit la position de ligne dans le fichier auquel l’élément |
| Namespace |
Obtient ou définit les espaces de noms contenant les attributs qui peuvent être utilisés. |
| Namespaces |
Obtient ou définit l’utilisation XmlSerializerNamespaces avec cet objet de schéma. (Hérité de XmlSchemaObject) |
| Parent |
Obtient ou définit le parent de ce XmlSchemaObject. (Hérité de XmlSchemaObject) |
| ProcessContents |
Obtient ou définit des informations sur la façon dont une application ou un processeur XML doit gérer la validation des documents XML pour les attributs spécifiés par l’élément |
| SourceUri |
Obtient ou définit l’emplacement source du fichier qui a chargé le schéma. (Hérité de XmlSchemaObject) |
| UnhandledAttributes |
Obtient ou définit les attributs qualifiés qui n’appartiennent pas à l’espace de noms cible du schéma actuel. (Hérité de XmlSchemaAnnotated) |
Méthodes
| Nom | Description |
|---|---|
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |