XPath generation question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

    #1

    XPath generation question

    Hi;

    We have a TreeView that represents an xml file (or it's schema is a more
    accurate statement). We want to have a double click on a node in the tree
    generate the XPath to get to that node.

    For the full tree it's easy. We walk up the parents getting the name of each
    node and put a / between each so we end up with /node1/node2 or
    node1/node2/@attr1

    Questions on this case:
    1) should we start with /node1 or self::/node1?
    2) if they click on the root should we use "self::" or "/"?

    We also have cases where we have a tree from a SelectNodes() and then want
    to handle a select from that. It seems to me that this case is no different -
    that in one case we have an XmlDocument and the other an XmlNodeList. But an
    XmlDocument is an XmlNode so is there a difference that matters between an
    XmlNode and an XmlNodeList?

    And if so, what should be the root of the xpath we create in this case?

    --
    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.


    Cubicle Wars - http://www.windwardreports.com/film.htm


  • Bjoern Hoehrmann

    #2
    Re: XPath generation question

    * David Thielen wrote in microsoft.publi c.dotnet.xml:
    >We have a TreeView that represents an xml file (or it's schema is a more
    >accurate statement). We want to have a double click on a node in the tree
    >generate the XPath to get to that node.
    >
    >For the full tree it's easy. We walk up the parents getting the name of each
    >node and put a / between each so we end up with /node1/node2 or
    >node1/node2/@attr1
    >
    >Questions on this case:
    >1) should we start with /node1 or self::/node1?
    >2) if they click on the root should we use "self::" or "/"?
    I don't think there is a good reason to use the self axis in either case
    and note that for the first question, your latter option is not valid
    syntax.
    >We also have cases where we have a tree from a SelectNodes() and then want
    >to handle a select from that. It seems to me that this case is no different -
    >that in one case we have an XmlDocument and the other an XmlNodeList. But an
    >XmlDocument is an XmlNode so is there a difference that matters between an
    >XmlNode and an XmlNodeList?
    Well, an XmlNode is a single node, whereas an XmlNodeList is one or more
    nodes, that seems an important difference but then I am not sure what
    you are really asking here.
    >And if so, what should be the root of the xpath we create in this case?
    It might be impossible to create one. Consider this case, you have two
    nodes in the node list like <a><b c=''/></aand <a><b c='' d=''/></a>,
    in order to create a path that would only match the c attribute in the
    former example, you would have to write it so that it won't match if a
    'd' attribute also occurs on the element. This might become arbitrarily
    complicated. Of course if the nodes are always from a single document,
    you would only look at single nodes and there would be no difference.
    --
    Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
    Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
    68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/

    Comment

    • =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?=

      #3
      Re: XPath generation question

      Hi;

      Sorry - self::node().

      We've found that self::node() works and "/" does not in some cases passing
      it to an XPathNavigator for SelectNodes().

      For your example we do not handle that case - what we handle is if they
      wanted the d='abc' attribute to equal a given value such as 'abc'.

      The issue is how should we build up the xpath for that query as we could be
      querying against an XmlDocument or an XPathNavigator that is at a location
      within the document?

      --
      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.


      Cubicle Wars - http://www.windwardreports.com/film.htm




      "Bjoern Hoehrmann" wrote:
      * David Thielen wrote in microsoft.publi c.dotnet.xml:
      We have a TreeView that represents an xml file (or it's schema is a more
      accurate statement). We want to have a double click on a node in the tree
      generate the XPath to get to that node.

      For the full tree it's easy. We walk up the parents getting the name of each
      node and put a / between each so we end up with /node1/node2 or
      node1/node2/@attr1

      Questions on this case:
      1) should we start with /node1 or self::/node1?
      2) if they click on the root should we use "self::" or "/"?
      >
      I don't think there is a good reason to use the self axis in either case
      and note that for the first question, your latter option is not valid
      syntax.
      >
      We also have cases where we have a tree from a SelectNodes() and then want
      to handle a select from that. It seems to me that this case is no different -
      that in one case we have an XmlDocument and the other an XmlNodeList. But an
      XmlDocument is an XmlNode so is there a difference that matters between an
      XmlNode and an XmlNodeList?
      >
      Well, an XmlNode is a single node, whereas an XmlNodeList is one or more
      nodes, that seems an important difference but then I am not sure what
      you are really asking here.
      >
      And if so, what should be the root of the xpath we create in this case?
      >
      It might be impossible to create one. Consider this case, you have two
      nodes in the node list like <a><b c=''/></aand <a><b c='' d=''/></a>,
      in order to create a path that would only match the c attribute in the
      former example, you would have to write it so that it won't match if a
      'd' attribute also occurs on the element. This might become arbitrarily
      complicated. Of course if the nodes are always from a single document,
      you would only look at single nodes and there would be no difference.
      --
      Björn Höhrmann · mailto:bjoern@h oehrmann.de · http://bjoern.hoehrmann.de
      Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
      68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
      >

      Comment

      • WenYuan Wang [MSFT]

        #4
        RE: XPath generation question

        Hi Dave,

        "/node1" in XPath means to search the node (node1) from the root.
        "self::node 1" in XPath means to search the node (node1) from the current
        node.
        If the current node is the root, there is no different between these two
        XPath.
        However, if the current node is not the root of XML, the result executed by
        these XPath will be different.

        For example:
        /
        -Node1
        -Node2
        -Node3
        -Node4
        -Node5

        If the current node is / (root), you can get the node(Node1) by both
        "/Node1" and "self::Node 1".
        But if the current node is the node(Node4), the XPath"/Node1" will work,
        but the "self::node 1" will return null. Additionally, if you want to a get
        the node(Node5), you should use "self::node 5" or "/node3/node4/node5". But
        "/node5" will return NULL.
        "self::node 5" is a relative location path and "/node3/node4/node5" is an
        absolute location path.
        >1) should we start with /node1 or self::/node1?
        I would like to start with "/node1", because it is the absolute location
        path.
        >2) if they click on the root should we use "self::" or "/"?
        I think "/" should be the root.

        Sorry! We can't seem to find the resource you're looking for

        [XPath Axes]

        Hope this helps.
        Sincerely,
        Wen Yuan
        Microsoft Online Community Support
        =============== =============== =============== =====
        Get notification to my posts through email? Please refer to
        http://msdn.microsoft.com/subscripti...ult.aspx#notif
        ications.

        Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
        where an initial response from the community or a Microsoft Support
        Engineer within 1 business day is acceptable. Please note that each follow
        up response may take approximately 2 business days as the support
        professional working with you may need further investigation to reach the
        most efficient resolution. The offering is not appropriate for situations
        that require urgent, real-time or phone-based interactions or complex
        project analysis and dump analysis issues. Issues of this nature are best
        handled working with a dedicated Microsoft Support Engineer by contacting
        Microsoft Customer Support Services (CSS) at
        http://msdn.microsoft.com/subscripti...t/default.aspx.
        =============== =============== =============== =====
        This posting is provided "AS IS" with no warranties, and confers no rights.

        Comment

        Working...