364,085 Members | 5185 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

adding namespace for an XPathDocument

LuAnn Bradford
P: n/a
LuAnn Bradford
I have read the messages about adding namespaces, but have not found how
to do so when using an XPathDocument instead of an XmlDocument.

I have an application that writes a dataset using WriteXML. The file
contains a default namespace. A second application reads the file using
the XPathDocument Load method. My Select expression will not work with
the default namespace.

I am very new to this and would appreciate any help!
LuAnn

Nov 11 '05 #1
Share this Question
Share on Google+
1 Reply


LuAnn Bradford
P: n/a
LuAnn Bradford
Found the answer...

XPathDocument doc = new XPathDocument( "name of XML file");
XPathNavigator nav = doc.CreateNavigator();
XmlNamespaceManager ns = new XmlNamespaceManager( nav.NameTable);
ns.AddNamespace( "usr", "http://tempuri.org/Users.xsd");
XPathExpression expr = nav.Compile( "//user:Users");
expr.SetContext( ns);
XPathNodeIterator nodes = nav.Select( expr);

The XPathNavigator object has a NameTable property. Hope that is helpful
to anyone having the same problem I was having.
LuAnn


LuAnn Bradford wrote:[color=blue]
> I have read the messages about adding namespaces, but have not found how
> to do so when using an XPathDocument instead of an XmlDocument.
>
> I have an application that writes a dataset using WriteXML. The file
> contains a default namespace. A second application reads the file using
> the XPathDocument Load method. My Select expression will not work with
> the default namespace.
>
> I am very new to this and would appreciate any help!
> LuAnn
>[/color]

Nov 11 '05 #2

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework