XmlDocument.Load 메서드

정의

지정된 XML 데이터를 Stream, URL, TextReader 또는 XmlReader에서 로드합니다.

오버로드

Load(Stream)

지정된 스트림에서 XML 문서를 로드합니다.

Load(TextReader)

지정된 TextReader에서 XML 문서를 로드합니다.

Load(String)

지정된 URL에서 XML 문서를 로드합니다.

Load(XmlReader)

지정된 XmlReader에서 XML 문서를 로드합니다.

Load(Stream)

Source:
XmlDocument.cs
Source:
XmlDocument.cs
Source:
XmlDocument.cs

지정된 스트림에서 XML 문서를 로드합니다.

public:
 virtual void Load(System::IO::Stream ^ inStream);
public virtual void Load (System.IO.Stream inStream);
abstract member Load : System.IO.Stream -> unit
override this.Load : System.IO.Stream -> unit
Public Overridable Sub Load (inStream As Stream)

매개 변수

inStream
Stream

로드할 XML 문서가 포함된 스트림입니다.

예외

XML에 로드 또는 구문 분석 오류가 있습니다. 이 경우 FileNotFoundException이 발생합니다.

설명

참고

메서드는 Load 항상 상당한 공백을 유지합니다. 속성은 PreserveWhitespace 요소 콘텐츠의 공백인 중요하지 않은 공백이 유지되는지 여부를 결정합니다. 기본값은 입니다 false. 요소 콘텐츠의 공백은 유지되지 않습니다.

유효성 검사를 수행하려면 클래스와 Create 메서드를 사용하여 XmlReaderSettings 유효성 XmlReader 검사 instance 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

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

이 메서드는 입력 XML의 문자열 형식(예: UTF-8, ANSI 등)을 자동으로 검색합니다. 스트림을 읽는 데 사용 되는 인코딩을 알아야 애플리케이션에 필요한 경우는 XmlTextReader 스트림의 읽을 개체를 사용 하 여는 XmlTextReader.Encoding 인코딩을 결정 하는 속성입니다. XML 작업을 위해 개체를 XmlDocument 사용해야 하는 경우 개체를 XmlTextReader 사용하여 만들 수 있습니다. 자세한 내용은 XPathDocument 및 XmlDocument를 사용하여 XML 데이터 읽기를 참조하세요.

추가 정보

적용 대상

Load(TextReader)

Source:
XmlDocument.cs
Source:
XmlDocument.cs
Source:
XmlDocument.cs

지정된 TextReader에서 XML 문서를 로드합니다.

public:
 virtual void Load(System::IO::TextReader ^ txtReader);
public virtual void Load (System.IO.TextReader txtReader);
abstract member Load : System.IO.TextReader -> unit
override this.Load : System.IO.TextReader -> unit
Public Overridable Sub Load (txtReader As TextReader)

매개 변수

txtReader
TextReader

XML 데이터를 문서에 제공하기 위해 사용하는 TextReader입니다.

예외

XML에 로드 또는 구문 분석 오류가 있습니다. 이 경우 문서는 빈 상태로 유지됩니다.

예제

다음 예제에서는 클래스를 StringReader 사용하여 XML 데이터 문자열을 개체에 로드합니다 XmlDocument .

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   String^ xmlData = "<book xmlns:bk='urn:samples'></book>";
   doc->Load( gcnew StringReader( xmlData ) );
   
   // Create a new element and add it to the document.
   XmlElement^ elem = doc->CreateElement( "bk", "genre", "urn:samples" );
   elem->InnerText = "fantasy";
   doc->DocumentElement->AppendChild( elem );
   Console::WriteLine( "Display the modified XML..." );
   doc->Save( Console::Out );
}

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {

    // Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    string xmlData = "<book xmlns:bk='urn:samples'></book>";

    doc.Load(new StringReader(xmlData));

    // Create a new element and add it to the document.
    XmlElement elem = doc.CreateElement("bk", "genre", "urn:samples");
    elem.InnerText = "fantasy";
    doc.DocumentElement.AppendChild(elem);

    Console.WriteLine("Display the modified XML...");
    doc.Save(Console.Out);
  }
}
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main() 

    ' Create the XmlDocument.
    Dim doc as XmlDocument = new XmlDocument()
    Dim xmlData as string = "<book xmlns:bk='urn:samples'></book>"

    doc.Load(new StringReader(xmlData))

    ' Create a new element and add it to the document.
    Dim elem as XmlElement = doc.CreateElement("bk", "genre", "urn:samples")
    elem.InnerText = "fantasy"
    doc.DocumentElement.AppendChild(elem)

    Console.WriteLine("Display the modified XML...")
    doc.Save(Console.Out)

  end sub
end class

설명

참고

메서드는 Load 항상 상당한 공백을 유지합니다. 속성은 PreserveWhitespace 요소 콘텐츠의 공백인 중요하지 않은 공백이 유지되는지 여부를 결정합니다. 기본값은 입니다 false. 요소 콘텐츠의 공백은 유지되지 않습니다.

유효성 검사를 수행하려면 클래스와 Create 메서드를 사용하여 XmlReaderSettings 유효성 XmlReader 검사 instance 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

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

추가 정보

적용 대상

Load(String)

Source:
XmlDocument.cs
Source:
XmlDocument.cs
Source:
XmlDocument.cs

지정된 URL에서 XML 문서를 로드합니다.

public:
 virtual void Load(System::String ^ filename);
public virtual void Load (string filename);
abstract member Load : string -> unit
override this.Load : string -> unit
Public Overridable Sub Load (filename As String)

매개 변수

filename
String

로드할 XML 문서가 포함된 파일의 URL입니다. URL은 로컬 파일 또는 HTTP URL(웹 주소)일 수 있습니다.

예외

XML에 로드 또는 구문 분석 오류가 있습니다. 이 경우 FileNotFoundException이 발생합니다.

filename가 빈 문자열이거나 공백만 포함하거나 InvalidPathChars로 정의된 하나 이상의 잘못된 문자를 포함합니다.

filename이(가) null인 경우

지정된 경로, 파일 이름 또는 둘 다가 시스템에서 정의한 최대 길이를 초과합니다.

지정된 경로가 잘못되었습니다(예: 매핑되지 않은 드라이브에 있음).

파일을 여는 동안 I/O 오류가 발생했습니다.

filename에 읽기 전용인 파일이 지정되었습니다.

또는

현재 플랫폼이 해당 작업을 지원하지 않는 경우

또는

filename에 디렉터리가 지정되었습니다.

또는

호출자에게 필요한 권한이 없는 경우

filename에 지정된 파일을 찾을 수 없습니다.

filename의 형식이 잘못되었습니다.

호출자에게 필요한 권한이 없는 경우

설명

참고

메서드는 Load 항상 상당한 공백을 유지합니다. 속성은 PreserveWhitespace 요소 콘텐츠의 공백인 중요하지 않은 공백이 유지되는지 여부를 결정합니다. 기본값은 입니다 false. 요소 콘텐츠의 공백은 유지되지 않습니다.

유효성 검사를 수행하려면 클래스와 Create 메서드를 사용하여 XmlReaderSettings 유효성 XmlReader 검사 instance 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

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

추가 정보

적용 대상

Load(XmlReader)

Source:
XmlDocument.cs
Source:
XmlDocument.cs
Source:
XmlDocument.cs

지정된 XmlReader에서 XML 문서를 로드합니다.

public:
 virtual void Load(System::Xml::XmlReader ^ reader);
public virtual void Load (System.Xml.XmlReader reader);
abstract member Load : System.Xml.XmlReader -> unit
override this.Load : System.Xml.XmlReader -> unit
Public Overridable Sub Load (reader As XmlReader)

매개 변수

reader
XmlReader

XML 데이터를 문서에 제공하기 위해 사용하는 XmlReader입니다.

예외

XML에 로드 또는 구문 분석 오류가 있습니다. 이 경우 문서는 빈 상태로 유지됩니다.

예제

다음 예제에서는 파일의 마지막 책 노드를 books.xml XML 문서에 로드합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   
   //Load the document with the last book node.
   XmlTextReader^ reader = gcnew XmlTextReader( "books.xml" );
   reader->WhitespaceHandling = WhitespaceHandling::None;
   reader->MoveToContent();
   reader->Read();
   reader->Skip(); //Skip the first book.
   reader->Skip(); //Skip the second book.
   doc->Load( reader );
   doc->Save( Console::Out );
}

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();

    //Load the document with the last book node.
    XmlTextReader reader = new XmlTextReader("books.xml");
    reader.WhitespaceHandling = WhitespaceHandling.None;
    reader.MoveToContent();
    reader.Read();
    reader.Skip(); //Skip the first book.
    reader.Skip(); //Skip the second book.
    doc.Load(reader);

    doc.Save(Console.Out);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        
        'Load the document with the last book node.
        Dim reader As New XmlTextReader("books.xml")
        reader.WhitespaceHandling = WhitespaceHandling.None
        reader.MoveToContent()
        reader.Read()
        reader.Skip() 'Skip the first book.
        reader.Skip() 'Skip the second book.
        doc.Load(reader)
        
        doc.Save(Console.Out)
    End Sub
End Class

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

<?xml version='1.0'?>
<!-- This file represents a fragment of a book store inventory database -->
<bookstore>
  <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
    <title>The Autobiography of Benjamin Franklin</title>
    <author>
      <first-name>Benjamin</first-name>
      <last-name>Franklin</last-name>
    </author>
    <price>8.99</price>
  </book>
  <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
    <title>The Confidence Man</title>
    <author>
      <first-name>Herman</first-name>
      <last-name>Melville</last-name>
    </author>
    <price>11.99</price>
  </book>
  <book genre="philosophy" publicationdate="1991" ISBN="1-861001-57-6">
    <title>The Gorgias</title>
    <author>
      <name>Plato</name>
    </author>
    <price>9.99</price>
  </book>
</bookstore>

설명

참고

메서드는 Load 항상 상당한 공백을 유지합니다. 속성은 PreserveWhitespace 요소 콘텐츠의 공백인 중요하지 않은 공백이 유지되는지 여부를 결정합니다. 기본값은 입니다 false. 요소 콘텐츠의 공백은 유지되지 않습니다.

판독기가 초기 상태(ReadState =ReadState.Initial) Load 인 경우 는 판독기의 전체 콘텐츠를 사용하고 찾은 내용에서 DOM을 빌드합니다.

판독기가 깊이 "n"의 일부 노드에 이미 배치된 경우 이 메서드는 해당 노드와 모든 후속 형제를 깊이 "n"을 닫는 끝 태그까지 로드합니다. 다음과 같은 결과가 표시됩니다.

현재 노드와 해당 형제가 다음과 같은 경우:

<!--comment--><element1>one</element1><element2>two</element2>

Load 는 문서에 두 개의 루트 수준 요소가 있을 수 없으므로 예외를 throw합니다. 현재 노드와 해당 형제가 다음과 같은 경우:

<!--comment--><?process instruction?><!--comment--></endtag>

Load 성공하지만 루트 수준 요소가 없으므로 불완전한 DOM 트리가 있습니다. 문서를 저장하기 전에 루트 수준 요소를 추가해야 합니다. 그렇지 않으면 Save 예외가 throw됩니다.

판독기가 문서의 루트 수준(예: 공백 또는 특성 노드)에 유효하지 않은 리프 노드에 배치된 경우 판독기는 루트에 사용할 수 있는 노드에 배치될 때까지 계속 읽습니다. 이때 문서가 로드되기 시작합니다.

유효성 검사를 수행하려면 클래스와 Create 메서드를 사용하여 XmlReaderSettings 유효성 XmlReader 검사 instance 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

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

추가 정보

적용 대상