Re: .NET equivalent to XSLT value-of select



THANK YOU.
I had tried the Evaluate method, but was missing the "string()" part of the
expression. Now it works perfectly!

"Martin Honnen" wrote:

>
>
> Trillium wrote:
>
>
> > I am trying to retrieve the text value of an element named "child2Element"
> > from an XML file in a .NET (v 1.1) with an XPath expression. In an XSLT
> > document I would use <xsl:value-of
> > select="rootElement/child1Element[@childId='110']/child2Element"/> (and this
> > does work fine in a transform). But I cannot seem to find the right method
> > or object in .NET. There seem to be a number of classes that can use XPath,
> > but I can't figure out which one I have to use to get just the text value of
> > a single element.
>
> With XSLT 1.0 <xsl:value-of select="xpathexpression"> gives you the
> string value of the Xpath expression, within .NET you can use an
> XPathNavigator and its method Evaluate where you would need to explictly
> call the XPath string function on your expression e.g.
>
> using System;
> using System.Xml;
> using System.Xml.XPath;
>
> public class Test2005050603 {
> public static void Main (string[] args) {
> // args[0] is the XML file URL,
> // args[1] the XPath expression
> XPathDocument xPathDocument = new XPathDocument(args[0]);
> XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
> string valueOf = (string) xPathNavigator.Evaluate("string(" + args2
> + ")");
> Console.WriteLine(valueOf);
> }
> }
>
> The method Evaluate is documented here:
> <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNavigatorClassEvaluateTopic.asp>
>
>
> --
>
> Martin Honnen --- MVP XML
> http://JavaScript.FAQTs.com/
>
.



Relevant Pages

  • Re: .NET equivalent to XSLT value-of select
    ... string value of the Xpath expression, within .NET you can use an XPathNavigator and its method Evaluate where you would need to explictly call the XPath string function on your expression e.g. ... public static void Main { ...
    (microsoft.public.dotnet.xml)
  • Re: How to retreive deepest XPath value from XML using VB.NET
    ... ' Dim xmlDocument As New XPathDocument ... ' If Not (deepestElement Is Nothing) Then ... ' Dim deepestNode As XPathNavigator = GetDeepestNode ... ByVal nodeTest As String) As XPathNavigator ...
    (microsoft.public.dotnet.xml)
  • Re: tdom xpath search
    ... what you intend; XPath 1.0 doesn't ... know string matching wild-cards. ... always the first seq-name child below sequence, ...
    (comp.lang.tcl)
  • Re: HTML-Seite parsen in Java??
    ... Ich habe genau sowas vor einiger Zeit gemacht und dabei gute Erfahrungen mit der Kombination TagSoup und XPath gemacht. ... Map<String, String> map; ... public Iterator getPrefixes(String namespaceURI) { ... } catch (XPathExpressionException e) { ...
    (de.comp.lang.java)
  • Re: How to retreive deepest XPath value from XML using VB.NET
    ... if I had an XML file like this: ... if (deepestElement!= null) { ... XPathNavigator deepestNode = GetDeepestNode; ... public static XPathNavigator GetDeepestNode (IXPathNavigable xmlInput, string nodeTest) { ...
    (microsoft.public.dotnet.xml)