XmlSchemaObject.Namespaces Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan atau mengatur XmlSerializerNamespaces untuk digunakan dengan objek skema ini.
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
Nilai Properti
Properti XmlSerializerNamespaces untuk objek skema.
Contoh
Dalam contoh berikut, awalan myImpPrefix ditambahkan pada tingkat elemen skema. Awalan kemudian digunakan untuk memenuhi syarat definisi yang diimpor dari 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
Contohnya menghasilkan XML berikut.
<?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>
Keterangan
Ini memberi Schema Object Model (SOM) kemampuan untuk menambahkan deklarasi xmlns. Ini berguna ketika Anda ingin mendeklarasikan awalan untuk memenuhi syarat deklarasi dari skema yang diimpor atau digunakan dalam atribut xpath dari elemen xs:selector.
Anda juga dapat menggunakan Namespaces properti untuk mengubah awalan namespace dalam skema. Misalnya, Anda dapat mengubah awalan yang digunakan oleh skema untuk namespace Skema XML W3C dari xs ke xsd seperti yang diilustrasikan dalam contoh berikut.
Dim namespaces As XmlSerializerNamespaces = New XmlSerializerNamespaces()
namespaces.Add("myChangedPrefix", "myImportNamespace");
s.Namespaces = namespaces;
XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
namespaces.Add("myChangedPrefix", "myImportNamespace");
s.Namespaces = namespaces;