XPathNavigator.Value Property
Gets the text value of the current node.
[Visual Basic] Public MustOverride ReadOnly Property Value As String [C#] public abstract string Value {get;} [C++] public: __property virtual String* get_Value() = 0; [JScript] public abstract function get Value() : String;
Property Value
The value returned depends on the NodeType of the node. If the node does not have a value, an empty element for example, String.Empty is returned. The following table defines the return value for each node type.
| Node Type | Value |
|---|---|
| Attribute | The value of the attribute. |
| Element | The InnerText of the element. |
| Comment | The content of the comment. |
| ProcessingInstruction | The entire content excluding the target. |
| Text | The content of the text node. |
| Whitespace | The white space between mark-up. |
| SignificantWhitespace | The white space between markup in a mixed content model or white space within an xml:space= 'preserve' scope. |
| Root | The InnerText of the root node. |
Example
[Visual Basic, C#, C++] The following example walks the node tree recursively and displays information on element and text nodes.
[Visual Basic] public shared sub RecursiveWalk(nav as XPathNavigator) select case nav.NodeType case XPathNodeType.Element if (nav.Prefix=String.Empty) Console.WriteLine("<{0}>", nav.LocalName) else Console.Write("<{0}:{1}>", nav.Prefix, nav.LocalName) Console.WriteLine(" "+ nav.NamespaceURI) end if case XPathNodeType.Text Console.WriteLine(" " + nav.Value) end select if ( nav.MoveToFirstChild() ) do RecursiveWalk(nav) loop while ( nav.MoveToNext() ) nav.MoveToParent() if (nav.NodeType = XPathNodeType.Element) Console.WriteLine("</{0}>", nav.Name) end if end if end sub [C#] public static void RecursiveWalk(XPathNavigator nav) { switch (nav.NodeType){ case XPathNodeType.Element: if (nav.Prefix==String.Empty) Console.WriteLine("<{0}>", nav.LocalName); else Console.Write("<{0}:{1}>", nav.Prefix, nav.LocalName); Console.WriteLine("\t"+ nav.NamespaceURI); break; case XPathNodeType.Text: Console.WriteLine("\t" + nav.Value); break; } if ( nav.MoveToFirstChild() ) { do{ RecursiveWalk(nav); } while ( nav.MoveToNext() ); nav.MoveToParent(); if (nav.NodeType == XPathNodeType.Element) Console.WriteLine("</{0}>", nav.Name); } } [C++] static void RecursiveWalk(XPathNavigator * nav) { switch (nav -> NodeType) { case XPathNodeType::Element: if (nav -> Prefix == String::Empty) Console::WriteLine(S"< {0}>", nav -> LocalName); else Console::Write(S"< {0}: {1}>", nav -> Prefix, nav -> LocalName); Console::WriteLine(S"\t {0}", nav -> NamespaceURI); break; case XPathNodeType::Text: Console::WriteLine(S"\t {0}", nav -> Value); break; } if (nav -> MoveToFirstChild()) { do { RecursiveWalk(nav); } while (nav -> MoveToNext()); nav -> MoveToParent(); if (nav -> NodeType == XPathNodeType::Element) Console::WriteLine(S"</ {0}>", nav -> Name); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
XPathNavigator Class | XPathNavigator Members | System.Xml.XPath Namespace