XmlDocument.PreserveWhitespace 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 menetapkan nilai yang menunjukkan apakah akan mempertahankan spasi kosong dalam konten elemen.
public:
property bool PreserveWhitespace { bool get(); void set(bool value); };
public bool PreserveWhitespace { get; set; }
member this.PreserveWhitespace : bool with get, set
Public Property PreserveWhitespace As Boolean
Nilai Properti
true untuk mempertahankan spasi kosong; jika tidak false. Defaultnya adalah false.
Contoh
Contoh berikut menunjukkan cara menghapus spasi kosong dari file.
using System;
using System.IO;
using System.Xml;
public class Sample
{
public static void Main()
{
//Load XML data which includes white space, but ignore
//any white space in the file.
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = false;
doc.Load("book.xml");
//Save the document as is (no white space).
Console.WriteLine("Display the modified XML...");
doc.PreserveWhitespace = true;
doc.Save(Console.Out);
}
}
Imports System.IO
Imports System.Xml
public class Sample
public shared sub Main()
'Load XML data which includes white space, but ignore
'any white space in the file.
Dim doc as XmlDocument = new XmlDocument()
doc.PreserveWhitespace = false
doc.Load("book.xml")
'Save the document as is (no white space).
Console.WriteLine("Display the modified XML...")
doc.PreserveWhitespace = true
doc.Save(Console.Out)
end sub
end class
Contohnya menggunakan file book.xml sebagai input.
<!--sample XML fragment-->
<book genre='novel' ISBN='1-861003-78' misc='sale-item'>
<title>The Handmaid's Tale</title>
<price>14.95</price>
</book>
Keterangan
Properti ini menentukan bagaimana ruang kosong ditangani selama proses pemuatan dan penyimpanan.
Jika PreserveWhitespace sebelum true atau Load dipanggil, simpul spasi kosong dipertahankan; jika tidak, jika properti ini , LoadXmlruang putih yang signifikan dipertahankanfalse, ruang kosong tidak.
Jika PreserveWhitespace sebelumnya true dipanggil, spasi kosong dalam dokumen dipertahankan dalam output; jika tidak, jika properti ini , Savefalsemengindentasi XmlDocument output secara otomatis.
Metode ini adalah ekstensi Microsoft ke Model Objek Dokumen (DOM).