Share via


XmlDocument.PreserveWhitespace 속성

정의

요소 콘텐츠에서 공백을 유지할지를 나타내는 값을 가져오거나 설정합니다.

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

속성 값

Boolean

공백을 유지하려면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예제

다음 예제에서는 파일에서 공백을 제거하는 방법을 보여줍니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Load XML data which includes white space, but ignore
   //any white space in the file.
   XmlDocument^ doc = gcnew 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 );
}

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

이 예제에서는 파일을 book.xml 입력으로 사용합니다.

<!--sample XML fragment-->
<book genre='novel' ISBN='1-861003-78' misc='sale-item'>
  <title>The Handmaid's Tale</title>
  <price>14.95</price>
</book>

설명

이 속성은 로드 및 저장 프로세스 중에 공백을 처리하는 방법을 결정합니다.

PreserveWhitespace true 앞에 Load 있거나 LoadXml 호출되면 공백 노드가 유지되고, 그렇지 않으면 이 속성이 false있으면 상당한 공백이 유지되고 공백은 유지되지 않습니다.

PreserveWhitespace true 이전 Save 이 호출되면 문서의 공백이 출력에 유지되고, 그렇지 않으면 이 속성이 XmlDocument false면 출력을 자동으로 들여쓰기합니다.

이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

적용 대상