XPathNavigator.ValueType プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XPathNavigator.ValueType プロパティの意味・解説 

XPathNavigator.ValueType プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

現在のノード.NET Framework Type取得します

名前空間: System.Xml.XPath
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

解説解説

ValueType プロパティは、現在のノードの型指定された値の .NET Framework Type取得します

たとえば、xs:int 型の要素は、既定では Int32 の ValueTypeなります。ただし、ValueType は、Int16 や Double など、xs:int割り当てることができる任意の有効な型である可能性あります

ノードが型を持たない場合xdt:untypedAtomic であるノードの型注釈等価なります。この場合ValueType プロパティノード文字列返します詳細については、「System.Xml クラスでの型のサポート」を参照してください

使用例使用例

contosoBooks.xml XML ファイルcontosoBooks.xsd XML スキーマ定義言語 (XSD: XML Schema Definition Language) スキーマ使用して、XPathNavigator オブジェクト作成する例を次に示しますValueType プロパティ使用して price 要素の型指定された値を表示し次に、ValueAs メソッド使用して文字列として返します

' Create an XmlReaderSettings object with the contosoBooks.xsd schema.
Dim settings As XmlReaderSettings = New
 XmlReaderSettings()
settings.Schemas.Add("http://www.contoso.com/books",
 "contosoBooks.xsd")
settings.ValidationType = ValidationType.Schema

' Create an XmlReader object with the contosoBooks.xml file and its
 schema.
Dim reader As XmlReader = XmlReader.Create("contosoBooks.xml",
 settings)

Dim document As XPathDocument = New
 XPathDocument(reader)
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToChild("bookstore", "http://www.contoso.com/books")
navigator.MoveToChild("book", "http://www.contoso.com/books")
navigator.MoveToChild("price", "http://www.contoso.com/books")

' Display the current type of the price element.
Console.WriteLine(navigator.ValueType)

' Get the value of the price element as a string and display it.
Dim price As String = navigator.ValueAs(GetType(String))
Console.WriteLine(price)
// Create an XmlReaderSettings object with the contosoBooks.xsd schema.
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add("http://www.contoso.com/books", "contosoBooks.xsd");
settings.ValidationType = ValidationType.Schema;

// Create an XmlReader object with the contosoBooks.xml file and its
 schema.
XmlReader reader = XmlReader.Create("contosoBooks.xml", settings);

XPathDocument document = new XPathDocument(reader);
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
navigator.MoveToChild("book", "http://www.contoso.com/books");
navigator.MoveToChild("price", "http://www.contoso.com/books");

// Display the current type of the price element.
Console.WriteLine(navigator.ValueType);

// Get the value of the price element as a string and display it.
string price = navigator.ValueAs(typeof(string))
 as string;
Console.WriteLine(price);

この例では、入力として、contosoBooks.xml というファイル使用してます。

<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography"
 publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The
 Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17"
 ISBN="0-201-63361-2">
        <title>The
 Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy"
 publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The
 Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

またこの例では、入力として、contosoBooks.xsd使用してます。

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
 elementFormDefault="qualified" targetNamespace="http://www.contoso.com/books"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="bookstore">
        <xs:complexType>
            <xs:sequence>
                <xs:element maxOccurs="unbounded"
 name="book">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element
 name="title" type="xs:string" />
                            <xs:element
 name="author">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element
 minOccurs="0" name="name" type="xs:string" />
                                        <xs:element
 minOccurs="0" name="first-name" type="xs:string"
 />
                                        <xs:element
 minOccurs="0" name="last-name" type="xs:string" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element
 name="price" type="xs:decimal" />
                        </xs:sequence>
                        <xs:attribute
 name="genre" type="xs:string" use="required" />
                        <xs:attribute
 name="publicationdate" type="xs:date" use="required"
 />
                        <xs:attribute
 name="ISBN" type="xs:string" use="required" />
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XPathNavigator クラス
XPathNavigator メンバ
System.Xml.XPath 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

XPathNavigator.ValueType プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XPathNavigator.ValueType プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS