XDocument.Load 메서드

정의

URI로 지정된 파일, XDocumentURI 또는 TextReader에서 새 XmlReader 파일을 만듭니다.

오버로드

Name Description
Load(Stream)

지정된 스트림을 사용하여 새 XDocument 인스턴스를 만듭니다.

Load(TextReader)

에서 새 XDocument 새 개체를 TextReader만듭니다.

Load(String)

파일에서 새 XDocument 파일을 만듭니다.

Load(XmlReader)

에서 새 XDocument 항목을 XmlReader만듭니다.

Load(Stream, LoadOptions)

지정된 스트림을 사용하고, 필요에 따라 공백을 유지하고, 기본 URI를 설정하고, 줄 정보를 유지하여 새 XDocument 인스턴스를 만듭니다.

Load(TextReader, LoadOptions)

필요에 따라 공백 유지XDocument, 기본 URI 설정 및 줄 정보 유지에서 새 TextReader 항목을 만듭니다.

Load(String, LoadOptions)

필요에 따라 공백을 유지하고, 기본 URI를 설정하고, 줄 정보를 유지하여 파일에서 새 XDocument 항목을 만듭니다.

Load(XmlReader, LoadOptions)

XDocument 필요에 따라 기본 URI를 XmlReader설정하고 줄 정보를 유지하여 원본에서 로드합니다.

설명

이 메서드의 오버로드 중 하나를 사용하여 파일, XDocumenta 또는 .에서 로드 TextReaderXmlReader수 있습니다.

XML이 XDocument 포함된 문자열에서 만들려면 .를 사용합니다 Parse.

Load(Stream)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

지정된 스트림을 사용하여 새 XDocument 인스턴스를 만듭니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::IO::Stream ^ stream);
public static System.Xml.Linq.XDocument Load(System.IO.Stream stream);
static member Load : System.IO.Stream -> System.Xml.Linq.XDocument
Public Shared Function Load (stream As Stream) As XDocument

매개 변수

stream
Stream

XML 데이터를 포함하는 스트림입니다.

반품

XDocument 스트림에 포함된 데이터를 읽는 개체입니다.

설명

로드 옵션을 제어하려면 매개 변수로 사용하는 Load 오버로드를 사용합니다LoadOptions.

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

수정 XmlReaderSettings해야 하는 경우 다음 단계를 수행합니다.

  1. XmlReader 매개 변수로 사용하는 Create 오버로드 중 XmlReaderSettings 하나를 호출하여 만듭니다.

  2. XmlReader 매개 변수로 사용하는 Load 오버로드 중 XDocument 하나에 전달합니다XmlReader.

적용 대상

Load(TextReader)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

에서 새 XDocument 새 개체를 TextReader만듭니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::IO::TextReader ^ textReader);
public static System.Xml.Linq.XDocument Load(System.IO.TextReader textReader);
static member Load : System.IO.TextReader -> System.Xml.Linq.XDocument
Public Shared Function Load (textReader As TextReader) As XDocument

매개 변수

textReader
TextReader

에 대한 콘텐츠가 들어 있는 TextReaderA XDocument 입니다.

반품

XDocument 지정된 TextReader내용이 들어 있는 항목입니다.

예제

다음 예제에서는 에서 문서를 StringReader만듭니다.

TextReader tr = new StringReader("<Root>Content</Root>");
XDocument doc = XDocument.Load(tr);
Console.WriteLine(doc);
Dim tr As TextReader = New StringReader("<Root>Content</Root>")
Dim doc As XDocument = XDocument.Load(tr)
Console.WriteLine(doc)

이 예제는 다음과 같은 출력을 생성합니다.

<Root>Content</Root>

설명

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

추가 정보

적용 대상

Load(String)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

파일에서 새 XDocument 파일을 만듭니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::String ^ uri);
public static System.Xml.Linq.XDocument Load(string uri);
static member Load : string -> System.Xml.Linq.XDocument
Public Shared Function Load (uri As String) As XDocument

매개 변수

uri
String

파일을 참조하여 새 XDocument파일로 로드하는 URI 문자열입니다.

반품

XDocument 지정된 파일의 내용이 들어 있는 항목입니다.

예제

다음 예제에서는 파일에서 로드하는 XDocument 방법을 보여줍니다.

이 예제에서는 다음 XML 문서를 사용합니다.

샘플 XML 파일: 일반적인 구매 주문(LINQ to XML)

XDocument doc = XDocument.Load("PurchaseOrder.xml");
Console.WriteLine(doc);
Dim doc As XDocument = XDocument.Load("PurchaseOrder.xml")
Console.WriteLine(doc)

이 예제는 다음과 같은 출력을 생성합니다.

<PurchaseOrder PurchaseOrderNumber="99503" OrderDate="1999-10-20">
  <Address Type="Shipping">
    <Name>Ellen Adams</Name>
    <Street>123 Maple Street</Street>
    <City>Mill Valley</City>
    <State>CA</State>
    <Zip>10999</Zip>
    <Country>USA</Country>
  </Address>
  <Address Type="Billing">
    <Name>Tai Yee</Name>
    <Street>8 Oak Avenue</Street>
    <City>Old Town</City>
    <State>PA</State>
    <Zip>95819</Zip>
    <Country>USA</Country>
  </Address>
  <DeliveryNotes>Please leave packages in shed by driveway.</DeliveryNotes>
  <Items>
    <Item PartNumber="872-AA">
      <ProductName>Lawnmower</ProductName>
      <Quantity>1</Quantity>
      <USPrice>148.95</USPrice>
      <Comment>Confirm this is electric</Comment>
    </Item>
    <Item PartNumber="926-AA">
      <ProductName>Baby Monitor</ProductName>
      <Quantity>2</Quantity>
      <USPrice>39.98</USPrice>
      <ShipDate>1999-05-21</ShipDate>
    </Item>
  </Items>
</PurchaseOrder>

설명

이 메서드는 기본 XmlReader 을 사용하여 XML 트리로 XML을 읽습니다.

XML을 Parse 포함하는 문자열에서 만드는 데 사용합니다XDocument.

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

추가 정보

적용 대상

Load(XmlReader)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

에서 새 XDocument 항목을 XmlReader만듭니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::Xml::XmlReader ^ reader);
public static System.Xml.Linq.XDocument Load(System.Xml.XmlReader reader);
static member Load : System.Xml.XmlReader -> System.Xml.Linq.XDocument
Public Shared Function Load (reader As XmlReader) As XDocument

매개 변수

reader
XmlReader

에 대한 콘텐츠가 들어 있는 XmlReaderA XDocument 입니다.

반품

XDocument 지정된 XmlReader내용이 들어 있는 항목입니다.

예제

다음 예제에서는 DOM 문서를 만들고, DOM 문서에서 만들고 XmlNodeReader , using를 XDocumentXmlNodeReader만듭니다.

// Create a DOM document with some content.
XmlDocument doc = new XmlDocument();
XmlElement child = doc.CreateElement("Child");
child.InnerText = "child contents";
XmlElement root = doc.CreateElement("Root");
root.AppendChild(child);
doc.AppendChild(root);

// create a reader and move to the content
using (XmlNodeReader nodeReader = new XmlNodeReader(doc)) {
    // the reader must be in the Interactive state in order to
    // create a LINQ to XML tree from it.
    nodeReader.MoveToContent();

    XDocument xRoot = XDocument.Load(nodeReader);
    Console.WriteLine(xRoot);
}
' Create a DOM document with some content.
Dim doc As XmlDocument = New XmlDocument()
Dim child As XmlElement = doc.CreateElement("Child")
child.InnerText = "child contents"
Dim root As XmlElement = doc.CreateElement("Root")
root.AppendChild(child)
doc.AppendChild(root)

' create a reader and move to the content
Using nodeReader = New XmlNodeReader(doc)
    ' the reader must be in the Interactive state in order to
    ' create a LINQ to XML tree from it.
    nodeReader.MoveToContent()

    Dim xRoot As XDocument = XDocument.Load(nodeReader)
    Console.WriteLine(xRoot)
End Using

이 예제는 다음과 같은 출력을 생성합니다.

<Root>
  <Child>child contents</Child>
</Root>

설명

이 메서드에 사용할 수 있는 한 가지 방법은 LINQ to XML 트리에 DOM 문서의 복사본을 만드는 것입니다. 이렇게 하려면 DOM 문서에서 만든 XmlNodeReader 다음 이 문서를 사용하여 XmlNodeReader 만듭니다 XDocument.

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

추가 정보

적용 대상

Load(Stream, LoadOptions)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

지정된 스트림을 사용하고, 필요에 따라 공백을 유지하고, 기본 URI를 설정하고, 줄 정보를 유지하여 새 XDocument 인스턴스를 만듭니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::IO::Stream ^ stream, System::Xml::Linq::LoadOptions options);
public static System.Xml.Linq.XDocument Load(System.IO.Stream stream, System.Xml.Linq.LoadOptions options);
static member Load : System.IO.Stream * System.Xml.Linq.LoadOptions -> System.Xml.Linq.XDocument
Public Shared Function Load (stream As Stream, options As LoadOptions) As XDocument

매개 변수

stream
Stream

XML 데이터를 포함하는 스트림입니다.

options
LoadOptions

기본 URI 및 줄 정보를 로드할지 여부를 지정하는 A LoadOptions 입니다.

반품

XDocument 스트림에 포함된 데이터를 읽는 개체입니다.

설명

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

수정 XmlReaderSettings해야 하는 경우 다음 단계를 수행합니다.

  1. XmlReader 매개 변수로 사용하는 오버로드 중 Create 하나를 호출하여 만듭니다XmlReaderSettings.

  2. XmlReader 매개 변수로 사용하는 Load 오버로드 중 XDocument 하나에 전달합니다XmlReader.

적용 대상

Load(TextReader, LoadOptions)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

필요에 따라 공백 유지XDocument, 기본 URI 설정 및 줄 정보 유지에서 새 TextReader 항목을 만듭니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::IO::TextReader ^ textReader, System::Xml::Linq::LoadOptions options);
public static System.Xml.Linq.XDocument Load(System.IO.TextReader textReader, System.Xml.Linq.LoadOptions options);
static member Load : System.IO.TextReader * System.Xml.Linq.LoadOptions -> System.Xml.Linq.XDocument
Public Shared Function Load (textReader As TextReader, options As LoadOptions) As XDocument

매개 변수

textReader
TextReader

에 대한 콘텐츠가 들어 있는 TextReaderA XDocument 입니다.

options
LoadOptions

공백 동작 및 기본 URI 및 줄 정보를 로드할지 여부를 지정하는 A LoadOptions 입니다.

반품

XDocument 지정된 TextReaderXML에서 읽은 XML을 포함하는 형식입니다.

예제

다음 예제에서는 에서 문서를 StringReader만듭니다.

TextReader sr;
int whiteSpaceNodes;

sr = new StringReader("<Root> <Child> </Child> </Root>");
XDocument xmlTree1 = XDocument.Load(sr, LoadOptions.None);
sr.Close();
whiteSpaceNodes = xmlTree1
    .Element("Root")
    .DescendantNodesAndSelf()
    .OfType<XText>()
    .Where(tNode => tNode.ToString().Trim().Length == 0)
    .Count();
Console.WriteLine("Count of white space nodes (not preserving whitespace): {0}", whiteSpaceNodes);

sr = new StringReader("<Root> <Child> </Child> </Root>");
XDocument xmlTree2 = XDocument.Load(sr, LoadOptions.PreserveWhitespace);
sr.Close();
whiteSpaceNodes = xmlTree2
    .Element("Root")
    .DescendantNodesAndSelf()
    .OfType<XText>()
    .Where(tNode => tNode.ToString().Trim().Length == 0)
    .Count();
Console.WriteLine("Count of white space nodes (preserving whitespace): {0}", whiteSpaceNodes);
Dim sr As TextReader
Dim whiteSpaceNodes As Integer

sr = New StringReader("<Root> <Child> </Child> </Root>")
Dim xmlTree1 As XDocument = XDocument.Load(sr, LoadOptions.None)
sr.Close()
whiteSpaceNodes = xmlTree1 _
              .Element("Root") _
              .DescendantNodesAndSelf() _
              .OfType(Of XText)() _
              .Where(Function(ByVal tNode As XNode) tNode. _
                  ToString().Trim().Length = 0).Count()
Console.WriteLine("Count of white space nodes (not preserving whitespace): {0}", whiteSpaceNodes)

sr = New StringReader("<Root> <Child> </Child> </Root>")
Dim xmlTree2 As XDocument = XDocument.Load(sr, LoadOptions.PreserveWhitespace)
sr.Close()
whiteSpaceNodes = xmlTree2 _
              .Element("Root") _
              .DescendantNodesAndSelf() _
              .OfType(Of XText)() _
              .Where(Function(ByVal tNode As XNode) tNode. _
                  ToString().Trim().Length = 0).Count()
Console.WriteLine("Count of white space nodes (preserving whitespace): {0}", whiteSpaceNodes)

이 예제는 다음과 같은 출력을 생성합니다.

Count of white space nodes (not preserving whitespace): 0
Count of white space nodes (preserving whitespace): 3

설명

원본 XML을 들여쓰는 경우 플래그 PreserveWhitespaceoptions 설정하면 판독기가 원본 XML의 모든 공백을 읽습니다. 형식 XText 의 노드는 중요하고 중요하지 않은 공백 모두에 대해 생성됩니다.

원본 XML을 들여쓰는 경우 플래그 PreserveWhitespaceoptions 설정하지 않으면 판독기가 원본 XML의 모든 중요하지 않은 공백을 무시하게 됩니다. XML 트리는 중요하지 않은 공백에 대한 텍스트 노드 없이 만들어집니다.

원본 XML을 들여쓰지 않으면 플래그 PreserveWhitespaceoptions 설정해도 효과가 없습니다. 상당한 공백은 여전히 유지되며, 더 많은 공백 텍스트 노드를 만들 수 있는 중요하지 않은 공백의 범위가 없습니다.

자세한 내용은 XML을 로드하거나 구문 분석하는 동안 공백 유지를 참조하고 직렬화하는 동안 공백을 유지합니다.

XML을 Parse 포함하는 문자열에서 만드는 데 사용합니다XElement.

에서 로드할 때 설정 SetBaseUriTextReader유효하지 않습니다.

플래그를 설정하면 성능 저하가 SetLineInfo 있습니다.

줄 정보는 XML 문서를 로드한 직후에 정확합니다. 문서를 로드한 후 XML 트리를 수정하면 줄 정보가 의미가 없게 될 수 있습니다.

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

추가 정보

적용 대상

Load(String, LoadOptions)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

필요에 따라 공백을 유지하고, 기본 URI를 설정하고, 줄 정보를 유지하여 파일에서 새 XDocument 항목을 만듭니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::String ^ uri, System::Xml::Linq::LoadOptions options);
public static System.Xml.Linq.XDocument Load(string uri, System.Xml.Linq.LoadOptions options);
static member Load : string * System.Xml.Linq.LoadOptions -> System.Xml.Linq.XDocument
Public Shared Function Load (uri As String, options As LoadOptions) As XDocument

매개 변수

uri
String

파일을 참조하여 새 XDocument파일로 로드하는 URI 문자열입니다.

options
LoadOptions

공백 동작 및 기본 URI 및 줄 정보를 로드할지 여부를 지정하는 A LoadOptions 입니다.

반품

XDocument 지정된 파일의 내용이 들어 있는 항목입니다.

예제

다음 예제에서는 파일에서 로드하는 XDocument 방법을 보여줍니다.

이 예제에서는 다음 XML 문서를 사용합니다.

샘플 XML 파일: 일반적인 구매 주문(LINQ to XML)

XDocument doc1 = XDocument.Load("PurchaseOrder.xml", LoadOptions.None);
Console.WriteLine("nodes if not preserving whitespace: {0}", doc1.DescendantNodes().Count());

XDocument doc2 = XDocument.Load("PurchaseOrder.xml", LoadOptions.PreserveWhitespace);
Console.WriteLine("nodes if preserving whitespace: {0}", doc2.DescendantNodes().Count());
Dim doc1 As XDocument = XDocument.Load("PurchaseOrder.xml", LoadOptions.None)
Console.WriteLine("nodes if not preserving whitespace: {0}", doc1.DescendantNodes().Count())

Dim doc2 As XDocument = XDocument.Load("PurchaseOrder.xml", LoadOptions.PreserveWhitespace)
Console.WriteLine("nodes if preserving whitespace: {0}", doc2.DescendantNodes().Count())

이 예제는 다음과 같은 출력을 생성합니다.

nodes if not preserving whitespace: 48
nodes if preserving whitespace: 82

설명

원본 XML을 들여쓰는 경우 플래그 PreserveWhitespaceoptions 설정하면 판독기가 원본 XML의 모든 공백을 읽습니다. 형식 XText 의 노드는 중요하고 중요하지 않은 공백 모두에 대해 생성됩니다.

원본 XML을 들여쓰는 경우 플래그 PreserveWhitespaceoptions 설정하지 않으면 판독기가 원본 XML의 모든 중요하지 않은 공백을 무시하게 됩니다. XML 트리는 중요하지 않은 공백에 대한 텍스트 노드 없이 만들어집니다.

원본 XML을 들여쓰지 않으면 플래그 PreserveWhitespaceoptions 설정해도 효과가 없습니다. 상당한 공백은 여전히 유지되며, 더 많은 공백 텍스트 노드를 만들 수 있는 중요하지 않은 공백의 범위가 없습니다.

자세한 내용은 XML을 로드하거나 구문 분석하는 동안 공백 유지를 참조하고 직렬화하는 동안 공백을 유지합니다.

XML을 Parse 포함하는 문자열에서 만드는 데 사용합니다XDocument.

플래그와 플래그를 설정 SetBaseUri 하면 성능이 저하됩니다 SetLineInfo .

XML 문서를 로드한 직후 기본 URI 및 줄 정보가 정확합니다. 문서를 로드한 후 XML 트리를 수정하면 기본 URI 및 줄 정보가 의미가 없게 될 수 있습니다.

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

추가 정보

적용 대상

Load(XmlReader, LoadOptions)

Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs
Source:
XDocument.cs

XDocument 필요에 따라 기본 URI를 XmlReader설정하고 줄 정보를 유지하여 원본에서 로드합니다.

public:
 static System::Xml::Linq::XDocument ^ Load(System::Xml::XmlReader ^ reader, System::Xml::Linq::LoadOptions options);
public static System.Xml.Linq.XDocument Load(System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options);
static member Load : System.Xml.XmlReader * System.Xml.Linq.LoadOptions -> System.Xml.Linq.XDocument
Public Shared Function Load (reader As XmlReader, options As LoadOptions) As XDocument

매개 변수

reader
XmlReader

의 내용XmlReader에 대해 읽을 A XDocument 입니다.

options
LoadOptions

기본 URI 및 줄 정보를 로드할지 여부를 지정하는 A LoadOptions 입니다.

반품

XDocument 지정된 XmlReaderXML에서 읽은 XML을 포함하는 형식입니다.

예제

다음 예제에서는 에서 로드하는 줄 정보를 로드합니다 XmlReader. 그런 다음, 줄 정보를 출력합니다.

string markup =
@"<Root>
    <Child>
        <GrandChild/>
    </Child>
</Root>";

// Create a reader and move to the content.
using (XmlReader nodeReader = XmlReader.Create(new StringReader(markup)))
{
    // the reader must be in the Interactive state in order to
    // Create a LINQ to XML tree from it.
    nodeReader.MoveToContent();

    XDocument xRoot = XDocument.Load(nodeReader, LoadOptions.SetLineInfo);
    Console.WriteLine("{0}{1}{2}",
        "Element Name".PadRight(20),
        "Line".PadRight(5),
        "Position");
    Console.WriteLine("{0}{1}{2}",
        "------------".PadRight(20),
        "----".PadRight(5),
        "--------");
    foreach (XElement e in xRoot.Elements("Root").DescendantsAndSelf())
        Console.WriteLine("{0}{1}{2}",
            ("".PadRight(e.Ancestors().Count() * 2) + e.Name).PadRight(20),
            ((IXmlLineInfo)e).LineNumber.ToString().PadRight(5),
            ((IXmlLineInfo)e).LinePosition);
}
Dim markup As String = _
    "<Root>" & Environment.NewLine & _
    "    <Child>" & Environment.NewLine & _
    "        <GrandChild/>" & Environment.NewLine & _
    "    </Child>" & Environment.NewLine & _
    "</Root>"

' Create a reader and move to the content.
Using nodeReader As XmlReader = XmlReader.Create(New StringReader(markup))

    ' The reader must be in the Interactive state in order to
    ' create a LINQ to XML tree from it.
    nodeReader.MoveToContent()

    Dim xRoot As XDocument = XDocument.Load(nodeReader, LoadOptions.SetLineInfo)
    Console.WriteLine("{0}{1}{2}", _
        "Element Name".PadRight(20), _
        "Line".PadRight(5), _
        "Position")
    Console.WriteLine("{0}{1}{2}", _
        "------------".PadRight(20), _
        "----".PadRight(5), _
        "--------")
    For Each e As XElement In xRoot.Elements("Root").DescendantsAndSelf()
        Console.WriteLine("{0}{1}{2}", _
            ("".PadRight(e.Ancestors().Count() * 2) & e.Name.ToString()).PadRight(20), _
            (DirectCast(e, IXmlLineInfo)).LineNumber.ToString().PadRight(5), _
            (DirectCast(e, IXmlLineInfo)).LinePosition)
    Next
End Using

이 예제는 다음과 같은 출력을 생성합니다.

Element Name        Line Position
------------        ---- --------
Root                1    2
  Child             2    6
    GrandChild      3    10

설명

DOM 문서에서 만든 XmlNodeReader 다음 이 메서드를 XmlNodeReader사용하여 XElement LINQ to XML 트리에서 DOM 문서의 복사본을 만들 수 있습니다.

XML을 Parse 포함하는 문자열에서 만드는 데 사용합니다XDocument.

에서 로드할 때 설정 PreserveWhitespaceXmlReader유효하지 않습니다. XmlReader 공백을 읽거나 읽지 않도록 구성됩니다. LINQ to XML 트리는 판독기에서 표시하는 공백 노드로 채워집니다. 설정 여부에 PreserveWhitespace 관계없이 동작이 됩니다.

XmlReader 유효한 기본 URI가 있을 수 있습니다. 설정하는 SetBaseUri경우 기본 URI는 XML 트리에서 보고 XmlReader되는 기본 URI에서 설정됩니다.

XmlReader 유효한 줄 정보가 있을 수 있습니다. 설정하는 SetLineInfo경우 줄 정보는 XML 트리에서 보고 XmlReader되는 줄 정보에서 설정됩니다.

플래그를 설정하면 성능 저하가 SetLineInfo 있습니다.

줄 정보는 XML 문서를 로드한 직후에 정확합니다. 문서를 로드한 후 XML 트리를 수정하면 줄 정보가 의미가 없게 될 수 있습니다.

LINQ to XML의 로드 기능은 기본으로 빌드됩니다 XmlReader. 따라서 오버로드 메서드 및 XmlReader.Create 문서를 읽고 구문 분석하는 메서드에 의해 XmlReader throw되는 예외를 catch할 수 있습니다.

추가 정보

적용 대상