XmlReader.ReadElementContentAsString 메서드

정의

현재 요소를 읽고 콘텐츠를 String 개체로 반환합니다.

오버로드

ReadElementContentAsString(String, String)

지정된 로컬 이름과 네임스페이스 URI가 현재 요소의 로컬 이름 및 네임스페이스 URI와 일치하는지 확인한 다음 현재 요소를 읽고 콘텐츠를 String 개체로 반환합니다.

ReadElementContentAsString()

현재 요소를 읽고 콘텐츠를 String 개체로 반환합니다.

ReadElementContentAsString(String, String)

지정된 로컬 이름과 네임스페이스 URI가 현재 요소의 로컬 이름 및 네임스페이스 URI와 일치하는지 확인한 다음 현재 요소를 읽고 콘텐츠를 String 개체로 반환합니다.

public:
 virtual System::String ^ ReadElementContentAsString(System::String ^ localName, System::String ^ namespaceURI);
public virtual string ReadElementContentAsString (string localName, string namespaceURI);
abstract member ReadElementContentAsString : string * string -> string
override this.ReadElementContentAsString : string * string -> string
Public Overridable Function ReadElementContentAsString (localName As String, namespaceURI As String) As String

매개 변수

localName
String

요소의 로컬 이름입니다.

namespaceURI
String

요소의 네임스페이스 URI입니다.

반환

String

요소 콘텐츠에 해당하는 String 개체입니다.

예외

XmlReader가 요소에 배치되지 않은 경우

또는

이전 비동기 작업이 완료되기 전에 XmlReader 메서드가 호출되었습니다. 이 경우 “비동기 작업이 이미 진행 중입니다.” 메시지를 나타내며 InvalidOperationException이 throw됩니다.

현재 요소에 자식 요소가 포함된 경우

또는

요소 콘텐츠를 String 개체로 변환할 수 없는 경우

메서드가 null 인수를 사용하여 호출된 경우

지정한 로컬 이름과 네임스페이스 URI가 읽고 있는 현재 요소의 로컬 이름 및 네임스페이스 URI와 일치하지 않는 경우

예제

다음 예제 stringValue 에서는 요소를 읽고 텍스트 콘텐츠를 반환합니다(주석 및 처리 명령 무시).

using (XmlReader reader = XmlReader.Create("dataFile.xml")) {
     reader.ReadToFollowing("stringValue");
     Console.WriteLine(reader.ReadElementContentAsString("stringValue", ""));
}
Using reader As XmlReader = XmlReader.Create("dataFile.xml")
  reader.ReadToFollowing("stringValue")
  Console.WriteLine(reader.ReadElementContentAsString("stringValue", ""))
End Using

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

<root>
  <stringValue>
     <!--comment-->
     <?some pi?>
      text value of the element.
  </stringValue>
  <longValue>270000000000001</longValue>
  <number>0</number>
  <double>2E10</double>
  <date>2003-01-08T15:00:00-00:00</date>
</root>

설명

이 메서드는 시작 태그, 요소의 내용을 읽고 판독기를 끝 요소 태그를 지나 이동합니다. 엔터티를 확장하고 처리 지침 및 주석을 무시합니다. 요소는 단순 콘텐츠만 포함할 수 있습니다. 즉, 자식 요소를 가질 수 없습니다.

자세한 내용은 참조 페이지의 설명 섹션 XmlReaderW3C XML 스키마 파트 2: Datatypes 권장 사항을 참조하세요 .

적용 대상

ReadElementContentAsString()

현재 요소를 읽고 콘텐츠를 String 개체로 반환합니다.

public:
 virtual System::String ^ ReadElementContentAsString();
public virtual string ReadElementContentAsString ();
abstract member ReadElementContentAsString : unit -> string
override this.ReadElementContentAsString : unit -> string
Public Overridable Function ReadElementContentAsString () As String

반환

String

요소 콘텐츠에 해당하는 String 개체입니다.

예외

XmlReader가 요소에 배치되지 않은 경우

또는

이전 비동기 작업이 완료되기 전에 XmlReader 메서드가 호출되었습니다. 이 경우 “비동기 작업이 이미 진행 중입니다.” 메시지를 나타내며 InvalidOperationException이 throw됩니다.

현재 요소에 자식 요소가 포함된 경우

또는

요소 콘텐츠를 String 개체로 변환할 수 없는 경우

메서드가 null 인수를 사용하여 호출된 경우

예제

다음 예제에서는 요소를 읽고 stringValue 텍스트 콘텐츠를 반환합니다(주석 및 처리 명령 무시).

using (XmlReader reader = XmlReader.Create("dataFile.xml")) {
     reader.ReadToFollowing("stringValue");
     Console.WriteLine(reader.ReadElementContentAsString());			
}
Using reader As XmlReader = XmlReader.Create("dataFile.xml")
  reader.ReadToFollowing("stringValue")
  Console.WriteLine(reader.ReadElementContentAsString())
End Using

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

<root>
  <stringValue>
     <!--comment-->
     <?some pi?>
      text value of the element.
  </stringValue>
  <longValue>270000000000001</longValue>
  <number>0</number>
  <double>2E10</double>
  <date>2003-01-08T15:00:00-00:00</date>
</root>

설명

이 메서드는 시작 태그, 요소의 내용을 읽고 판독기를 끝 요소 태그를 지나 이동합니다. 엔터티를 확장하고 처리 지침 및 주석을 무시합니다. 요소는 간단한 콘텐츠만 포함할 수 있습니다. 즉, 자식 요소를 가질 수 없습니다.

자세한 내용은 참조 페이지의 설명 섹션 XmlReaderW3C XML 스키마 2부: Datatypes 권장 사항을 참조하세요.

이 메서드의 비동기 버전은 다음을 참조하세요 ReadElementContentAsStringAsync.

적용 대상