XPathNavigator.ValueType Gets the .NET Framework Type of the current node. : XPathNavigator « XML « C# / C Sharp






XPathNavigator.ValueType Gets the .NET Framework Type of the current node.

 
using System;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml.XPath;
public class MainClass
{
    public static void Main()
    {
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.Schemas.Add("http://www.domain.com/books", "domainBooks.xsd");
        settings.ValidationType = ValidationType.Schema;

        XmlReader reader = XmlReader.Create("domainBooks.xml", settings);

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

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

        Console.WriteLine(navigator.ValueType);

        string price = navigator.ValueAs(typeof(string)) as string;
        Console.WriteLine(price);
    }
}
/*

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.domain.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>

*/

   
  








Related examples in the same category

1.XPathNavigator.AppendChild Creates a child node using XML data string
2.XPathNavigator.AppendChildElement Creates a child element node at the end of the list
3.XPathNavigator.CanEdit indicates whether the XPathNavigator can edit the underlying XML data.
4.XPathNavigator.Clone creates a XPathNavigator positioned at the same node.
5.XPathNavigator.CreateAttribute creates attribute node using namespace prefix, local name and namespace URI
6.XPathNavigator.CreateAttributes returns an XmlWriter to create new attributes
7.XPathNavigator.DeleteRange deletes a range of sibling nodes
8.XPathNavigator.DeleteSelf deletes the current node and its child nodes.
9.XPathNavigator.Evaluate evaluates XPath expression and returns typed result
10.XPathNavigator.Evaluate Uses context to evaluate the XPathExpression
11.XPathNavigator.InnerXml Gets or sets the markup representing the child nodes
12.XPathNavigator.InsertAfter creates a sibling node after the selected node
13.XPathNavigator.InsertAfter creates node after the selected node
14.XPathNavigator.InsertBefore creates a new sibling node before the selected node
15.XPathNavigator.InsertElementAfter
16.XPathNavigator.Matches tells whether the current node matches the specified XPathExpression.
17.XPathNavigator.MoveToFirstAttribute moves XPathNavigator to the first attribute of the current node.
18.XPathNavigator.MoveToFollowing moves XPathNavigator to the element with the local name and namespace URI
19.XPathNavigator.NavigatorComparer Gets an IEqualityComparer used for equality comparison of XPathNavigator objects.
20.XPathNavigator.OuterXml gets or sets the markup of the current node and its child nodes.
21.XPathNavigator.PrependChild creates child node at the beginning
22.XPathNavigator.PrependChildElement
23.XPathNavigator.ReadSubtree reads the current node and its child nodes.
24.XPathNavigator.ReplaceRange replaces a range of sibling nodes
25.XPathNavigator.ReplaceSelf replaces the current node
26.XPathNavigator.Select Selects a node set, using the specified XPath expression.
27.XPathNavigator.SelectAncestors selects all the ancestor nodes of the current
28.XPathNavigator.SelectSingleNode selects a single node in XPathNavigator using XPath query
29.XPathNavigator.SetTypedValue Sets the typed value of the current node.
30.XPathNavigator.SetValue Sets the value of the current node.
31.XPathNavigator.ValueAsBoolean Gets the current node's value as a Boolean.
32.XPathNavigator.WriteSubtree outputs node and its child nodes to the XmlWriter