XPath + SelectSingleNode

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

    XPath + SelectSingleNode

    Hi All,

    I have this weird problem. I have an xml document and tried to do an XPath
    query to it. If I use the SelectSingleNod e method it throws an exception but
    it works with SelectNodes method. Is this a known problem with XPath and
    SelectSingleNod e?

    Code snippet:

    <snip>
    XmlDocument xml= new XmlDocument();
    xml.LoadXml(xml String);


    XmlNamespaceMan ager namespaceManage r =
    new XmlNamespaceMan ager(xml.NameTa ble);

    namespaceManage r.AddNamespace( "defns", defns);

    // return xml.DocumentEle ment.SelectSing leNode(xpath, namespaceManage r);
    <-- does not work
    return xml.DocumentEle ment.SelectNode s(xpath, namespaceManage r); // WORKS!

    </snip>

    so ... this is odd, does anyone has any explanation?


    thanks,

    /m


  • Oleg Tkachenko

    #2
    Re: XPath + SelectSingleNod e

    muscha wrote:
    [color=blue]
    > I have this weird problem. I have an xml document and tried to do an XPath
    > query to it. If I use the SelectSingleNod e method it throws an exception but
    > it works with SelectNodes method. Is this a known problem with XPath and
    > SelectSingleNod e?[/color]

    That's really weird, because SelectSingleNod e is in fact only a wrapper around
    SelectNodes, which returns only first selected node.
    Provide more information please - what is your XML and XPath expression.
    --
    Oleg Tkachenko

    Multiconn Technologies, Israel

    Comment

    • Daniel Cazzulino

      #3
      Re: XPath + SelectSingleNod e

      I'd say the problem is in the method definition. Maybe it's defined to
      return an XmlNodeList and when you do the return from SelectSingleNod e it
      doesn't work.... just an idea...

      --
      .../d:cazz


      Daniel Cazzulino
      DEVerest - Lagash
      Tel +54 (0) 11 4247 7396


      dotnetopensrc.s ourceforge.net

      Coauthor of:
      Beginning C# Web Applications with Visual Studio .NET
      Beginning Web Programming using VB.NET and Visual Studio .NET
      Professional ASP.NET Server Controls: Building Custom Controls with C#
      ASP.NET Components Toolkit

      "He who is good for making excuses, is seldom good for anything else."

      "muscha" <muscha@no.spam .net> wrote in message
      news:%23W4$cqVg DHA.2084@TK2MSF TNGP10.phx.gbl. ..[color=blue]
      > Hi All,
      >
      > I have this weird problem. I have an xml document and tried to do an XPath
      > query to it. If I use the SelectSingleNod e method it throws an exception[/color]
      but[color=blue]
      > it works with SelectNodes method. Is this a known problem with XPath and
      > SelectSingleNod e?
      >
      > Code snippet:
      >
      > <snip>
      > XmlDocument xml= new XmlDocument();
      > xml.LoadXml(xml String);
      >
      >
      > XmlNamespaceMan ager namespaceManage r =
      > new XmlNamespaceMan ager(xml.NameTa ble);
      >
      > namespaceManage r.AddNamespace( "defns", defns);
      >
      > // return xml.DocumentEle ment.SelectSing leNode(xpath, namespaceManage r);
      > <-- does not work
      > return xml.DocumentEle ment.SelectNode s(xpath, namespaceManage r); // WORKS!
      >
      > </snip>
      >
      > so ... this is odd, does anyone has any explanation?
      >
      >
      > thanks,
      >
      > /m
      >
      >[/color]


      Comment

      • muscha

        #4
        Re: XPath + SelectSingleNod e

        > > I have this weird problem. I have an xml document and tried to do an
        XPath[color=blue][color=green]
        > > query to it. If I use the SelectSingleNod e method it throws an exception[/color][/color]
        but[color=blue][color=green]
        > > it works with SelectNodes method. Is this a known problem with XPath and
        > > SelectSingleNod e?[/color]
        >
        > That's really weird, because SelectSingleNod e is in fact only a wrapper[/color]
        around[color=blue]
        > SelectNodes, which returns only first selected node.
        > Provide more information please - what is your XML and XPath expression.[/color]

        You're right. It was a problem on my XPath. Found that it works now for
        SelectSingleNod e and even if I pass XPath that returns multiple nodes it
        will return the first occurance of the node.

        thanks

        /m


        Comment

        Working...