XmlReader.ReadElementContentAsObject メソッド ()
アセンブリ: System.Xml (system.xml.dll 内)

Dim instance As XmlReader Dim returnValue As Object returnValue = instance.ReadElementContentAsObject
最も適切な型のボックス化された共通言語ランタイム (CLR) オブジェクト。ValueType プロパティは、適切な CLR 型を判断します。内容がリスト型として型指定されている場合、このメソッドは適切な型のボックス化されたオブジェクトの配列を返します。


このメソッドは、開始タグと要素の内容を順に読み取り、リーダーを終了要素タグの後に移動します。エンティティを展開し、処理命令およびコメントを無視します。この要素には、単純な内容だけを格納できます。つまり、子要素は格納できません。
詳細については、「型指定されたデータの読み取り」および W3C 勧告『XML Schema Part 2: Datatypes』(http://www.w3.org/TR/xmlschema-2/) を参照してください。

このメソッドを使用して price ノードの内容を読み取る例を次に示します。リーダーは、スキーマ内の情報を使用して内容を正しいデータ型に割り当てます。
' 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)
// 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);
この例では、次の 2 つのファイルを入力として使用しています。
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>

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlReader.ReadElementContentAsObject メソッド (String, String)
アセンブリ: System.Xml (system.xml.dll 内)

Public Overridable Function ReadElementContentAsObject ( _ localName As String, _ namespaceURI As String _ ) As Object
Dim instance As XmlReader Dim localName As String Dim namespaceURI As String Dim returnValue As Object returnValue = instance.ReadElementContentAsObject(localName, namespaceURI)
戻り値
最も適切な型のボックス化された共通言語ランタイム (CLR) オブジェクト。ValueType プロパティは、適切な CLR 型を判断します。内容がリスト型として型指定されている場合、このメソッドは適切な型のボックス化されたオブジェクトの配列を返します。


このメソッドは、開始タグと要素の内容を順に読み取り、リーダーを終了要素タグの後に移動します。エンティティを展開し、処理命令およびコメントを無視します。この要素には、単純な内容だけを格納できます。つまり、子要素は格納できません。
詳細については、「型指定されたデータの読み取り」および W3C 勧告『XML Schema Part 2: Datatypes』(http://www.w3.org/TR/xmlschema-2/) を参照してください。

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlReader.ReadElementContentAsObject メソッド

名前 | 説明 |
---|---|
XmlReader.ReadElementContentAsObject () | 現在の要素を読み込み、その内容を Object として返します。 .NET Compact Framework によってサポートされています。 |
XmlReader.ReadElementContentAsObject (String, String) | 指定されたローカル名と名前空間 URI が現在の要素のものと一致することを確認し、現在の要素を読み込んで内容を Object として返します。 .NET Compact Framework によってサポートされています。 |

Weblioに収録されているすべての辞書からXmlReader.ReadElementContentAsObjectを検索する場合は、下記のリンクをクリックしてください。

- XmlReader.ReadElementContentAsObjectのページへのリンク