XmlReader.ReadInnerXml 메서드

정의

파생 클래스에서 재정의되면 태그를 포함한 모든 콘텐츠를 문자열로 읽습니다.

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>

ReadInnerXmlthis <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을 확인합니다. 가 에서 XmlValidatingReader호출되는 경우 ReadInnerXml 이 메서드는 반환된 콘텐츠의 유효성도 검사합니다.

XmlNodeReaderXmlTextReader 구현 된 , 및 XmlValidatingReader 클래스 메서드는 ReadOuterXml 네임 스페이스 인식 합니다.

이 메서드의 비동기 버전은 를 참조하세요 ReadInnerXmlAsync.

적용 대상