all groups > c# > april 2008 >
You're in the

c#

group:

Using System.Xml.XPath;


Using System.Xml.XPath; Tammy Nejadian
4/21/2008 10:27:00 PM
c#:
Hi, I am using Visual C# window creating an application to read an xml file.
At some point I need to use XPathNavigator and XPathNodeIterator however
when I used those subjects I get error message . I add the "System.Xml.XPath"
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
--
Re: Using System.Xml.XPath; Tammy Nejadian
4/22/2008 5:34:02 AM
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


[quoted text, click to view]
Re: Using System.Xml.XPath; Marc Gravell
4/22/2008 7:57:50 AM
[quoted text, click to view]
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?

[quoted text, click to view]
That is a namespace

[quoted text, click to view]
The XPathNavigator base-class is abstract; there are several private
implementations, but you shouldn't generally need to use them directly.


[quoted text, click to view]
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...

Re: Using System.Xml.XPath; Tammy Nejadian
4/22/2008 11:10:01 AM
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


[quoted text, click to view]
Re: Using System.Xml.XPath; Marc Gravell
4/22/2008 1:24:13 PM
[quoted text, click to view]

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.XPath;
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.CreateNavigator();
nav.MoveToFollowing("some", "");
string val = nav.GetAttribute("value", "");

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

}
}
Re: Using System.Xml.XPath; Marc Gravell
4/22/2008 1:46:09 PM
It sounds like you are either missing a "using" directive at the top of
the file:

using System.Xml.XPath;

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

AddThis Social Bookmark Button