XmlTextReader.GetRemainder 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
버퍼링된 XML의 나머지 부분을 가져옵니다.
public:
System::IO::TextReader ^ GetRemainder();
public System.IO.TextReader GetRemainder ();
member this.GetRemainder : unit -> System.IO.TextReader
Public Function GetRemainder () As TextReader
반환
버퍼링된 XML 의 나머지 부분을 포함하는 TextReader입니다.
예제
다음 예제에서는 XML 문서의 첫 번째 부분을 읽은 다음 두 번째 판독기를 사용하여 문서 읽기를 완료하는 데 사용합니다 GetRemainder
.
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
int main()
{
String^ filename = "tworeads.xml";
XmlTextReader^ reader = gcnew XmlTextReader( filename );
reader->WhitespaceHandling = WhitespaceHandling::None;
// Read the first part of the XML document
while ( reader->Read() )
{
// Display the elements and stop reading on the book endelement tag
// then go to ReadPart2 to start another reader to read the rest of the file.
switch ( reader->NodeType )
{
case XmlNodeType::Element:
Console::WriteLine( "Name: {0}", reader->Name );
break;
case XmlNodeType::Text:
Console::WriteLine( " Element Text: {0}", reader->Value );
break;
case XmlNodeType::EndElement:
// Stop reading when the reader gets to the end element of the book node.
if ( "book" == reader->LocalName )
{
Console::WriteLine( "End reading first book..." );
Console::WriteLine();
goto ReadPart2;
}
break;
}
}
// Read the rest of the XML document
ReadPart2:
Console::WriteLine( "Begin reading second book..." );
// Create a new reader to read the rest of the document.
XmlTextReader^ reader2 = gcnew XmlTextReader( reader->GetRemainder() );
while ( reader2->Read() )
{
switch ( reader2->NodeType )
{
case XmlNodeType::Element:
Console::WriteLine( "Name: {0}", reader2->Name );
break;
case XmlNodeType::Text:
Console::WriteLine( " Element Text: {0}", reader2->Value );
break;
case XmlNodeType::EndElement:
// Stop reading when the reader gets to the end element of the book node.
if ( "book" == reader2->LocalName )
{
Console::WriteLine( "End reading second book..." );
goto Done;
}
break;
}
}
Done:
Console::WriteLine( "Done." );
reader->Close();
reader2->Close();
}
using System;
using System.Xml;
public class Sample {
private static string filename = "tworeads.xml";
public static void Main() {
XmlTextReader reader = new XmlTextReader(filename);
reader.WhitespaceHandling=WhitespaceHandling.None;
// Read the first part of the XML document
while(reader.Read()) {
// Display the elements and stop reading on the book endelement tag
// then go to ReadPart2 to start another reader to read the rest of the file.
switch(reader.NodeType) {
case XmlNodeType.Element:
Console.WriteLine("Name: {0}", reader.Name);
break;
case XmlNodeType.Text:
Console.WriteLine(" Element Text: {0}", reader.Value);
break;
case XmlNodeType.EndElement:
// Stop reading when the reader gets to the end element of the book node.
if ("book"==reader.LocalName) {
Console.WriteLine("End reading first book...");
Console.WriteLine();
goto ReadPart2;
}
break;
}
}
// Read the rest of the XML document
ReadPart2:
Console.WriteLine("Begin reading second book...");
// Create a new reader to read the rest of the document.
XmlTextReader reader2 = new XmlTextReader(reader.GetRemainder());
while(reader2.Read()) {
switch (reader2.NodeType) {
case XmlNodeType.Element:
Console.WriteLine("Name: {0}", reader2.Name);
break;
case XmlNodeType.Text:
Console.WriteLine(" Element Text: {0}", reader2.Value);
break;
case XmlNodeType.EndElement:
// Stop reading when the reader gets to the end element of the book node.
if ("book"==reader2.LocalName) {
Console.WriteLine("End reading second book...");
goto Done;
}
break;
}
}
Done:
Console.WriteLine("Done.");
reader.Close();
reader2.Close();
}
}//End class
Imports System.Xml
Public Class Sample
Private Shared filename As String = "tworeads.xml"
Public Shared Sub Main()
Dim reader As New XmlTextReader(filename)
reader.WhitespaceHandling = WhitespaceHandling.None
' Read the first part of the XML document
While reader.Read()
' Display the elements and stop reading on the book endelement tag
' then go to ReadPart2 to start another reader to read the rest of the file.
Select Case reader.NodeType
Case XmlNodeType.Element
Console.WriteLine("Name: {0}", reader.Name)
Case XmlNodeType.Text
Console.WriteLine(" Element Text: {0}", reader.Value)
Case XmlNodeType.EndElement
' Stop reading when the reader gets to the end element of the book node.
If "book" = reader.LocalName Then
Console.WriteLine("End reading first book...")
Console.WriteLine()
GoTo ReadPart2
End If
End Select
End While
' Read the rest of the XML document
ReadPart2:
Console.WriteLine("Begin reading second book...")
' Create a new reader to read the rest of the document.
Dim reader2 As New XmlTextReader(reader.GetRemainder())
While reader2.Read()
Select Case reader2.NodeType
Case XmlNodeType.Element
Console.WriteLine("Name: {0}", reader2.Name)
Case XmlNodeType.Text
Console.WriteLine(" Element Text: {0}", reader2.Value)
Case XmlNodeType.EndElement
'Stop reading when the reader gets to the end element of the book node.
If "book" = reader2.LocalName Then
Console.WriteLine("End reading second book...")
GoTo Done
End If
End Select
End While
Done:
Console.WriteLine("Done.")
reader.Close()
reader2.Close()
End Sub
End Class
이 예제에서는 입력 파일을 tworeads.xml
사용합니다.
<?xml version="1.0" ?>
<bookstore>
<book>
<title>Pride And Prejudice</title>
<author>Jane Austen</author>
</book>
<book>
<title>The Handmaid's Tale</title>
<author>Margaret Atwood</author>
</book>
</bookstore>
설명
참고
.NET Framework 2.0부터 새 기능을 활용하기 위해 메서드를 사용하여 XmlReader.Create 인스턴스를 만드는 XmlReader 것이 좋습니다.
XmlTextReader 버퍼링되므로 Read
데이터가 손실되지 않도록 사용되지 않는 버퍼의 나머지 부분을 반환할 수 있어야 합니다. 이렇게 하면 프로토콜(예: 다중 파트 MIME)이 다른 것과 동일한 스트림에서 XML을 패키지할 수 있습니다.
이 메서드를 호출한 EOF 후 .로 설정됩니다 true
.