XPathNavigator and name()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Thielen

    #1

    XPathNavigator and name()

    Hi;

    Two questions. I have an XPathNavigator object where it's OuterXml property
    is "<jan>231</jan>" and I am trying to write an xpath statement that will
    return the "jan".

    XPathNavigator nav = ...;

    1) I can do nav.Evaluate("n ame(parent::*)" ); and get "month". But if I do
    nav.Evaluate("n ame(self::*)"); I get "" returned. Shouldn't I get "jan"?

    2) This is for code that can be passed random xpath statements. For some it
    seems I need to call nav.SelectSingl eNode(xpath) and for some (the name()
    example) nav.Evaluate(). Is there any way to have a single call that handles
    any xpath?

    --
    thanks - dave
    david_at_windwa rd_dot_net
    Windward's document generation software provides a unique low-code solution that enables users to design custom, data-connected templates within the familiar landscape of Microsoft Office. Windward is fast, easy, and removes human error, transforming the way business professionals create documents.


  • Kevin Yu [MSFT]

    #2
    RE: XPathNavigator and name()

    Hi Dave,

    Thanks for posting!

    1. I tried to reproduce it, but with my code below, it is working fine. The
    object returns "jan".

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<M onth><jan>231</jan></Month>");
    XPathNavigator nav = doc.CreateNavig ator();
    XPathNavigator n = nav.SelectSingl eNode("//Month/jan");
    object o = n.Evaluate("nam e(self::*)");

    Could you show me your code that can repro it? Thanks.

    2. The SelectSingleNod e method does different things from Evaluate method.
    SelectSingleNod e does an XPath query and returns another XPathNavigator, so
    that you can move to another node with it.

    However, Evaluate method evaluates an XPath expression and returns result.
    It will be converted to an object.

    Kevin Yu
    Microsoft Online Community Support

    =============== =============== =============== =============== =============== =
    =============== ===========
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    =============== =============== =============== =============== =============== =
    =============== ===========

    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Comment

    • David Thielen

      #3
      RE: XPathNavigator and name()

      I swear this wasn't working yesterday - but it work now. I must have types
      something wrong without realizing it.

      --
      thanks - dave
      david_at_windwa rd_dot_net
      Windward's document generation software provides a unique low-code solution that enables users to design custom, data-connected templates within the familiar landscape of Microsoft Office. Windward is fast, easy, and removes human error, transforming the way business professionals create documents.




      "Kevin Yu [MSFT]" wrote:
      Hi Dave,
      >
      Thanks for posting!
      >
      1. I tried to reproduce it, but with my code below, it is working fine. The
      object returns "jan".
      >
      XmlDocument doc = new XmlDocument();
      doc.LoadXml("<M onth><jan>231</jan></Month>");
      XPathNavigator nav = doc.CreateNavig ator();
      XPathNavigator n = nav.SelectSingl eNode("//Month/jan");
      object o = n.Evaluate("nam e(self::*)");
      >
      Could you show me your code that can repro it? Thanks.
      >
      2. The SelectSingleNod e method does different things from Evaluate method.
      SelectSingleNod e does an XPath query and returns another XPathNavigator, so
      that you can move to another node with it.
      >
      However, Evaluate method evaluates an XPath expression and returns result.
      It will be converted to an object.
      >
      Kevin Yu
      Microsoft Online Community Support
      >
      =============== =============== =============== =============== =============== =
      =============== ===========
      When responding to posts, please "Reply to Group" via your newsreader so
      that others may learn and benefit from your issue.
      =============== =============== =============== =============== =============== =
      =============== ===========
      >
      (This posting is provided "AS IS", with no warranties, and confers no
      rights.)
      >
      >

      Comment

      • Kevin Yu [MSFT]

        #4
        RE: XPathNavigator and name()

        No problem, Dave. Anyway, it was nice to know that it's working for you.

        If you have any questions, please feel free to post them in the community.

        Kevin Yu
        Microsoft Online Community Support

        =============== =============== =============== =============== =============== =
        =============== ===========
        When responding to posts, please "Reply to Group" via your newsreader so
        that others may learn and benefit from your issue.
        =============== =============== =============== =============== =============== =
        =============== ===========

        (This posting is provided "AS IS", with no warranties, and confers no
        rights.)

        Comment

        Working...