Why does this X-path gives an error ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • apurvaG
    New Member
    • Apr 2007
    • 14

    Why does this X-path gives an error ???

    Hi All,

    Am getting an error while selecting nodes from my XML document. But if I change the "X-path" expression used it is working fine. Can anyone help me to undestand what is wrong with my X-path?

    Following X-path expression is giving error.

    xmldom.SelectNo des("//[protype='abc' and proflag='1']")

    Above line of code gives following exception in VS2005 [vb.net]
    Run-time exception thrown : System.Xml.XPat h.XPathExceptio n - Expression must evaluate to a node-set.


    But if I give the x-path as follows then it is working fine.
    xmldom.SelectNo des("//proxml[protype='abc' and proflag='1']")

    Can anyone tell why '//[condition]" does not work and "//node[condition]" works ?

    Here is the sample XML which I am using.
    <proxml>
    <protype>abc</protype>
    <prouid>demo</prouid>
    <proflag>1</proflag>
    </proxml>

    Thanking you in advace
    Apurva G.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    It creates an error because you have not specified the node the condition (in brackets) applies to.. Use a * or proxml as shown.
    Code:
    xmldom.SelectNodes("//*[protype='abc' and proflag='1']")

    Comment

    • apurvaG
      New Member
      • Apr 2007
      • 14

      #3
      Originally posted by jkmyoung
      It creates an error because you have not specified the node the condition (in brackets) applies to.. Use a * or proxml as shown.
      Code:
      xmldom.SelectNodes("//*[protype='abc' and proflag='1']")
      --------------------------
      Thanks jkmyoung for the reply.

      Comment

      Working...