XmlSchemaObject.Namespaces Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta l'oggetto XmlSerializerNamespaces da utilizzare con questo oggetto schema.
public:
property System::Xml::Serialization::XmlSerializerNamespaces ^ Namespaces { System::Xml::Serialization::XmlSerializerNamespaces ^ get(); void set(System::Xml::Serialization::XmlSerializerNamespaces ^ value); };
public System.Xml.Serialization.XmlSerializerNamespaces Namespaces { get; set; }
member this.Namespaces : System.Xml.Serialization.XmlSerializerNamespaces with get, set
Public Property Namespaces As XmlSerializerNamespaces
Valore della proprietà
Proprietà XmlSerializerNamespaces per l'oggetto schema.
Esempio
Nell'esempio seguente il prefisso myImpPrefix viene aggiunto a livello di elemento dello schema. Il prefisso viene quindi usato per qualificare le definizioni importate da myImportNamespace.
using System;
using System.Xml;
using System.Xml.Schema;
class XmlSchemaObject
{
public static void Main()
{
XmlSchema s = new XmlSchema();
s.TargetNamespace = "myNamespace";
s.Namespaces.Add("myImpPrefix", "myImportNamespace");
// Create the <xs:import> element.
XmlSchemaImport import = new XmlSchemaImport();
import.Namespace = "myImportNamespace";
import.SchemaLocation = "http://www.example.com/myImportNamespace";
s.Includes.Add(import);
// Create an element and assign a type from imported schema.
XmlSchemaElement elem = new XmlSchemaElement();
elem.SchemaTypeName = new XmlQualifiedName("importType", "myImportNamespace");
elem.Name = "element1";
s.Items.Add(elem);
s.Write(Console.Out);
}
}
Imports System.Xml
Imports System.Xml.Schema
Class XmlSchemaObject
Public Shared Sub Main()
Dim s As New XmlSchema()
s.TargetNamespace = "myNamespace"
s.Namespaces.Add("myImpPrefix", "myImportNamespace")
' Create the <xs:import> element.
Dim import As New XmlSchemaImport()
import.Namespace = "myImportNamespace"
import.SchemaLocation = "http://www.example.com/myImportNamespace"
s.Includes.Add(import)
' Create an element and assign a type from imported schema.
Dim elem As New XmlSchemaElement()
elem.SchemaTypeName = New XmlQualifiedName("importType", "myImportNamespace")
elem.Name = "element1"
s.Items.Add(elem)
s.Write(Console.Out)
End Sub
End Class
L'esempio produce il codice XML seguente.
<?xml version="1.0" encoding="IBM437"?>
<schema xmlns:myImpPrefix="myImportNamespace" targetNamespace="myNamespace" xmlns="http://www.w3.org/2001/XMLSchema">
<import schemaLocation="http://www.microsoft.com/myImportNamespace" namespace="myImportNamespace" />
<element name="element1" type="myImpPrefix:importType" />
</schema>
Commenti
In questo modo, schema object model (SOM) è possibile aggiungere dichiarazioni xmlns. Ciò è utile quando si desidera dichiarare un prefisso per qualificare le dichiarazioni da uno schema importato o usarlo nell'attributo xpath dell'elemento xs:selector.
È anche possibile usare la Namespaces proprietà per modificare i prefissi dello spazio dei nomi in uno schema. Ad esempio, è possibile modificare il prefisso usato da uno schema per lo spazio dei nomi W3C XML Schema da xs a xsd, come illustrato nell'esempio seguente.
Dim namespaces As XmlSerializerNamespaces = New XmlSerializerNamespaces()
namespaces.Add("myChangedPrefix", "myImportNamespace");
s.Namespaces = namespaces;
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("myChangedPrefix", "myImportNamespace");
s.Namespaces = namespaces;