XmlReader.ReadInnerXml 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
파생 클래스에서 재정의된 경우 태그를 포함한 모든 콘텐츠를 문자열로 읽습니다.
public:
virtual System::String ^ ReadInnerXml();
public virtual string ReadInnerXml();
abstract member ReadInnerXml : unit -> string
override this.ReadInnerXml : unit -> string
Public Overridable Function ReadInnerXml () As String
반품
현재 노드의 모든 XML 콘텐츠(태그 포함)입니다. 현재 노드에 자식이 없으면 빈 문자열이 반환됩니다.
현재 노드가 요소나 특성이 아니면 빈 문자열이 반환됩니다.
예외
XML의 형식이 잘못되었거나 XML을 구문 분석하는 동안 오류가 발생했습니다.
XmlReader 이전 비동기 작업이 완료되기 전에 메서드가 호출되었습니다. 이 경우 InvalidOperationException "비동기 작업이 이미 진행 중입니다."라는 메시지와 함께 throw됩니다.
예제
다음 예제에서는 메서드와 ReadOuterXml 메서드를 ReadInnerXml 비교합니다.
// Load the file and ignore all white space.
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
using (XmlReader reader = XmlReader.Create("2books.xml")) {
// Moves the reader to the root element.
reader.MoveToContent();
// Moves to book node.
reader.Read();
// Note that ReadInnerXml only returns the markup of the node's children
// so the book's attributes are not returned.
Console.WriteLine("Read the first book using ReadInnerXml...");
Console.WriteLine(reader.ReadInnerXml());
// ReadOuterXml returns the markup for the current node and its children
// so the book's attributes are also returned.
Console.WriteLine("Read the second book using ReadOuterXml...");
Console.WriteLine(reader.ReadOuterXml());
}
' Load the file and ignore all white space.
Dim settings As New XmlReaderSettings()
settings.IgnoreWhitespace = True
Using reader As XmlReader = XmlReader.Create("2books.xml")
' Moves the reader to the root element.
reader.MoveToContent()
' Moves to book node.
reader.Read()
' Note that ReadInnerXml only returns the markup of the node's children
' so the book's attributes are not returned.
Console.WriteLine("Read the first book using ReadInnerXml...")
Console.WriteLine(reader.ReadInnerXml())
' ReadOuterXml returns the markup for the current node and its children
' so the book's attributes are also returned.
Console.WriteLine("Read the second book using ReadOuterXml...")
Console.WriteLine(reader.ReadOuterXml())
End Using
이 예제에서는 파일을 입력으로 사용합니다 2books.xml .
<!--sample XML fragment-->
<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>
설명
이 메서드는 태그를 포함하여 현재 노드의 모든 콘텐츠를 반환합니다. 현재 노드(시작 태그) 및 해당 엔드 노드(끝 태그)가 반환되지 않습니다. 예를 들어 다음이 있는 경우
<node>
this <child id="123"/>
</node>
ReadInnerXml
this <child id="123"/>를 반환합니다
이 메서드는 다음과 같은 방식으로 요소 및 특성 노드를 처리합니다.
| 노드 유형 | 통화 전 위치 | XML 조각 | 반환 값 | 통화 후 위치 지정 |
|---|---|---|---|---|
Element |
시작 태그에 있습니다 item1 . |
<item1>text1</item1><item2>text2</item2> | text1 | 시작 태그에 있습니다 item2 . |
Attribute |
특성 노드에서 attr1 |
<item attr1="val1" attr2="val2">text</item> | val1 | 특성 노드에 attr1 남아 있습니다. |
판독기를 리프 노드에 배치하는 경우 호출은 호출 ReadInnerXmlRead과 동일합니다. 메서드가 반환됩니다 String.Empty (특성 노드를 제외하고 특성 값이 반환됨).
이 메서드는 올바른 형식의 XML을 확인합니다.
ReadInnerXml 이 메서드는 반환된 XmlValidatingReader콘텐츠의 유효성을 검사합니다.
및 클래스에 XmlNodeReaderXmlTextReaderXmlValidatingReader 구현된 대로 메서드는 ReadOuterXml 네임스페이스를 인식합니다.
이 메서드의 비동기 버전은 다음을 참조하세요 ReadInnerXmlAsync.