Using System.Xml.XPath;

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

    Using System.Xml.XPath;

    Hi, I am using Visual C# window creating an application to read an xml file.
    At some point I need to use XPathNavigator and XPathNodeIterat or however
    when I used those subjects I get error message . I add the "System.Xml.XPa th"
    class however it either empty or not implemented. This problem happened also
    when I was going to use FlowLayoutPanel . How I can activate the above
    classes? Do I need to instal something? Thanks
    --
    Nejadian
  • Marc Gravell

    #2
    Re: Using System.Xml.XPat h;

    At some point I need to use XPathNavigator and XPathNodeIterat or
    What makes you think that? In most cass, something like XmlDocument or
    XDocument work fine and don't require explicit use of either of these...
    Can you state what you are trying to do? Perhaps with example (if
    broken) code?
    I add the "System.Xml.XPa th" class
    That is a namespace
    however it either empty or not implemented.
    The XPathNavigator base-class is abstract; there are several private
    implementations , but you shouldn't generally need to use them directly.

    This problem happened also when I was going to use FlowLayoutPanel .
    I strongly suspect this was unrelated; you'd need to indicate the
    specific (ideally copy and paste verbatim) error message to give a
    meaningful answer...

    Marc

    Comment

    • =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?=

      #3
      Re: Using System.Xml.XPat h;

      This the error message I am getting: The type or namespace name
      'XPathNavigator ' could not be found (are you missing a using directive or an
      assembly reference?)

      --
      Nejadian


      "Marc Gravell" wrote:
      At some point I need to use XPathNavigator and XPathNodeIterat or
      What makes you think that? In most cass, something like XmlDocument or
      XDocument work fine and don't require explicit use of either of these...
      Can you state what you are trying to do? Perhaps with example (if
      broken) code?
      >
      I add the "System.Xml.XPa th" class
      That is a namespace
      >
      however it either empty or not implemented.
      The XPathNavigator base-class is abstract; there are several private
      implementations , but you shouldn't generally need to use them directly.
      >
      >
      This problem happened also when I was going to use FlowLayoutPanel .
      I strongly suspect this was unrelated; you'd need to indicate the
      specific (ideally copy and paste verbatim) error message to give a
      meaningful answer...
      >
      Marc
      >

      Comment

      • Marc Gravell

        #4
        Re: Using System.Xml.XPat h;

        It sounds like you are either missing a "using" directive at the top of
        the file:

        using System.Xml.XPat h;

        Or you are missing a reference to System.Xml - but either way, you don't
        necessarily need to use an XPathNavigator to edit xml...

        Marc

        Comment

        • =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?=

          #5
          Re: Using System.Xml.XPat h;

          I already had that using directive on the top and it still giving me the
          error message. That is way I posted this question.l
          --
          Nejadian


          "Marc Gravell" wrote:
          It sounds like you are either missing a "using" directive at the top of
          the file:
          >
          using System.Xml.XPat h;
          >
          Or you are missing a reference to System.Xml - but either way, you don't
          necessarily need to use an XPathNavigator to edit xml...
          >
          Marc
          >

          Comment

          • Marc Gravell

            #6
            Re: Using System.Xml.XPat h;

            I already had that using directive on the top and it still giving me the
            error message. That is way I posted this question.l
            OK, but you still haven't included nearly enough information to answer
            anything here... unless you count telepathy.

            An example using a navigator is below, but to be honest I've never had
            to directly use a navigator, and I've done "more than a bit" of xml...
            if this doesn't compile, or doesn't work (and you are sure you have
            the System.Xml reference), then you are going to have to supply some
            kind of information if you want help... for example:

            * what version of .NET are you using? 1.1 / 2.0 / 3.0 / 3.5 / ...
            * what tool are you using? VS2005 / VS2008 / csc / MSBuild / ...
            * have you got a short, complete example of the code that doesn't
            work? Like how mine is a short, complete example of code that works
            (on my machine, at least).

            Marc

            using System.Xml;
            using System.Xml.XPat h;
            static class Program {
            static void Main()
            {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(@"< xml><test><some value=""abc""/></test></xml>");

            // using a navigator
            XPathNavigator nav = doc.CreateNavig ator();
            nav.MoveToFollo wing("some", "");
            string val = nav.GetAttribut e("value", "");

            // but why bother? SelectNodes / SelectSingleNod e does the job
            fine...
            XmlElement el = (XmlElement)doc .SelectSingleNo de("/xml/test/
            some");
            val = el.GetAttribute ("value");

            }
            }

            Comment

            Working...