XmlReader.ReadElementContentAsObject 메서드

정의

현재 요소를 읽고 내용을 />로 반환합니다.

오버로드

Name Description
ReadElementContentAsObject()

현재 요소를 읽고 내용을 />로 반환합니다.

ReadElementContentAsObject(String, String)

지정된 로컬 이름 및 네임스페이스 URI가 현재 요소의 이름과 일치하는지 확인한 다음, 현재 요소를 읽고 내용을 반환 Object합니다.

ReadElementContentAsObject()

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

현재 요소를 읽고 내용을 />로 반환합니다.

public:
 virtual System::Object ^ ReadElementContentAsObject();
public virtual object ReadElementContentAsObject();
abstract member ReadElementContentAsObject : unit -> obj
override this.ReadElementContentAsObject : unit -> obj
Public Overridable Function ReadElementContentAsObject () As Object

반품

가장 적합한 형식의 BOXED CLR(공용 언어 런타임) 개체입니다. 속성은 ValueType 적절한 CLR 형식을 결정합니다. 콘텐츠가 목록 형식으로 입력되면 이 메서드는 적절한 형식의 boxed 개체 배열을 반환합니다.

예외

XmlReader 요소에 위치하지 않습니다.

-또는-

XmlReader 이전 비동기 작업이 완료되기 전에 메서드가 호출되었습니다. 이 경우 InvalidOperationException "비동기 작업이 이미 진행 중입니다."라는 메시지와 함께 throw됩니다.

현재 요소에는 자식 요소가 포함됩니다.

-또는-

요소 콘텐츠를 요청된 형식으로 변환할 수 없습니다.

메서드는 인수를 사용하여 null 호출됩니다.

예제

다음 예제에서는 메서드를 사용하여 노드의 내용을 읽습니다 price . 판독기는 스키마의 정보를 사용하여 콘텐츠를 올바른 데이터 형식에 매핑합니다.

// Create a validating reader.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:items", "item.xsd");	
 XmlReader reader = XmlReader.Create("item.xml", settings);

// Get the CLR type of the price element.
reader.ReadToFollowing("price");
Console.WriteLine(reader.ValueType);

// Return the value of the price element as Decimal object.
Decimal price = (Decimal) reader.ReadElementContentAsObject();

// Add 2.50 to the price.
price = Decimal.Add(price, 2.50m);
' Create a validating reader.
Dim settings As New XmlReaderSettings()
settings.ValidationType = ValidationType.Schema
settings.Schemas.Add("urn:items", "item.xsd")
Dim reader As XmlReader = XmlReader.Create("item.xml", settings)
      
' Get the CLR type of the price element. 
reader.ReadToFollowing("price")
Console.WriteLine(reader.ValueType)
      
' Return the value of the price element as Decimal object.
Dim price As [Decimal] = CType(reader.ReadElementContentAsObject(), [Decimal])
      
' Add 2.50 to the price.
price = [Decimal].Add(price, 2.5D)

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

item.xml

<item xmlns="urn:items" productID='123098'>
 <name>hammer</name>
 <price>9.95</price>
 <supplierID>1929</supplierID>
</item>

item.xsd

<?xml version="1.0"?>
<xs:schema xmlns:tns="urn:items" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="urn:items" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="item">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="name" type="xs:string" />
        <xs:element name="price" type="xs:decimal" />
        <xs:element name="supplierID" type="xs:unsignedShort" />
      </xs:sequence>
      <xs:attribute name="productID" type="xs:unsignedInt" use="required" />
    </xs:complexType>
  </xs:element>
</xs:schema>

설명

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

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

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

적용 대상

ReadElementContentAsObject(String, String)

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

지정된 로컬 이름 및 네임스페이스 URI가 현재 요소의 이름과 일치하는지 확인한 다음, 현재 요소를 읽고 내용을 반환 Object합니다.

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

매개 변수

localName
String

요소의 로컬 이름입니다.

namespaceURI
String

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

반품

가장 적합한 형식의 BOXED CLR(공용 언어 런타임) 개체입니다. 속성은 ValueType 적절한 CLR 형식을 결정합니다. 콘텐츠가 목록 형식으로 입력되면 이 메서드는 적절한 형식의 boxed 개체 배열을 반환합니다.

예외

XmlReader 요소에 위치하지 않습니다.

-또는-

XmlReader 이전 비동기 작업이 완료되기 전에 메서드가 호출되었습니다. 이 경우 InvalidOperationException "비동기 작업이 이미 진행 중입니다."라는 메시지와 함께 throw됩니다.

현재 요소에는 자식 요소가 포함됩니다.

-또는-

요소 콘텐츠를 요청된 형식으로 변환할 수 없습니다.

메서드는 인수를 사용하여 null 호출됩니다.

지정된 로컬 이름 및 네임스페이스 URI가 읽는 현재 요소의 이름과 일치하지 않습니다.

설명

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

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

적용 대상