XNamespace.Xmlns 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.
XNamespace Mendapatkan objek yang sesuai dengan URI xmln (http://www.w3.org/2000/xmlns/).
public:
static property System::Xml::Linq::XNamespace ^ Xmlns { System::Xml::Linq::XNamespace ^ get(); };
public static System.Xml.Linq.XNamespace Xmlns { get; }
static member Xmlns : System.Xml.Linq.XNamespace
Public Shared ReadOnly Property Xmlns As XNamespace
Nilai Properti
XNamespace yang sesuai dengan URI xmln (http://www.w3.org/2000/xmlns/).
Contoh
Contoh berikut menunjukkan cara menambahkan namespace ke pohon XML. Namespace untuk atribut yang mendeklarasikan namespace adalah namespace yang dikembalikan oleh properti ini.
XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root",
new XAttribute(XNamespace.Xmlns + "aw", "http://www.adventure-works.com"),
new XElement(aw + "Child", "content")
);
Console.WriteLine(root);
Dim root = <aw:Root xmlns:aw="http://www.adventure-works.com">
<aw:Child>content</aw:Child>
</aw:Root>
Console.WriteLine(root)
Dalam Visual Basic, idiom pilihan adalah:
Imports <xmlns:aw='http://www.adventure-works.com'>
Module Module1
Sub Main()
Dim root As XElement = _
<aw:Root>
<aw:Child>content</aw:Child>
</aw:Root>
Console.WriteLine(root)
End Sub
End Module
Contoh ini menghasilkan output berikut:
<aw:Root xmlns:aw="http://www.adventure-works.com">
<aw:Child>content</aw:Child>
</aw:Root>
Keterangan
Saat Anda mendeklarasikan namespace layanan, atribut namespace itu sendiri berada di namespace xmln . Standar W3C menentukan bahwa namespace layanan ini tidak harus dideklarasikan sebagai atribut di pohon XML. Ini adalah namespace layanan yang dipesan yang selalu tersedia secara otomatis di pengurai XML.