Hi,
I can't figure out for the life of me how to select nodes using a namespace
in XpathNavigator. For example:
XPathDocument doc = new XPathDocument(" file.xml");
XPathNavigator nav = doc.CreateNavig ator();
XPathNodeIterat or itr = nav.Select("/foo:bar");
Throws the exception "Namespace Manager or XsltContext needed. This query
has a prefix, variable, or user-defined function"
I notice that the Select() function of XmlDocument allows me to supply a an
XmlNamespaceMan ager object as a parameter, but neither XPathDocument or
XPathNavigator seem to have any such feature.
I'm happy to create an XmlNamespaceMan ager if someone could please explain
exactly where I should put it :)
Andy 4 17540
Andy Fish wrote: I can't figure out for the life of me how to select nodes using a namespace in XpathNavigator. For example:
XPathDocument doc = new XPathDocument(" file.xml"); XPathNavigator nav = doc.CreateNavig ator(); XPathNodeIterat or itr = nav.Select("/foo:bar");
Throws the exception "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function"
I notice that the Select() function of XmlDocument allows me to supply a an XmlNamespaceMan ager object as a parameter, but neither XPathDocument or XPathNavigator seem to have any such feature.
I'm happy to create an XmlNamespaceMan ager if someone could please explain exactly where I should put it :)
In .NET 2.0 there is additional overload that accepts string expression
and IXmlNamespaceRe solver (XmlNamespaceMa nager implements it) - see http://msdn2.microsoft.com/en-us/library/6k4x060d.aspx.
In .NET 1.1 you have no choice but to compile XPathExpression manually:
XPathExpression expr = nav.Compile("bo ok/@bk:ISBN");
XmlNamespaceMan ager mngr = new XmlNamespaceMan ager(new NameTable());
mngr.AddNamespa ce("bk","urn:sa mples");
expr.SetContext (mngr);
XPathNodeIterat or ni = nav.Select(expr );
See http://msdn.microsoft.com/library/de...lecttopic2.asp
--
Oleg Tkachenko [XML MVP, MCAD] http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
> In .NET 1.1 you have no choice but to compile XPathExpression manually:
XPathExpression expr = nav.Compile("bo ok/@bk:ISBN"); XmlNamespaceMan ager mngr = new XmlNamespaceMan ager(new NameTable()); mngr.AddNamespa ce("bk","urn:sa mples"); expr.SetContext (mngr); XPathNodeIterat or ni = nav.Select(expr );
Thanks Oleg, it works a treat (but what a polaver though).
One small follow-up if I may. I would have thought that if I initialized the
namespace manager like this:
XmlNamespaceMan ager mngr = new XmlNamespaceMan ager(nav.NameTa ble);
then it would pick up the namespace prefixes from the document. However, it
doesn't (I still need to do the AddNamespace calls)
TIA
Andy
Andy Fish wrote: One small follow-up if I may. I would have thought that if I initialized the namespace manager like this:
XmlNamespaceMan ager mngr = new XmlNamespaceMan ager(nav.NameTa ble);
then it would pick up the namespace prefixes from the document. However, it doesn't (I still need to do the AddNamespace calls)
No, first of all NameTable has nothing to do with namespaces - it's just
a collection of atomic strings (names) used to save memory and speed
up name comparisons. Second - there is no such thing as "prefixes from
the document" as in XML document namespace prefixes can be overriden and
undeclared in any order.
--
Oleg Tkachenko [XML MVP, MCAD] http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Andy Fish wrote: One small follow-up if I may. I would have thought that if I initialized the namespace manager like this:
XmlNamespaceMan ager mngr = new XmlNamespaceMan ager(nav.NameTa ble);
then it would pick up the namespace prefixes from the document. However, it doesn't (I still need to do the AddNamespace calls)
The NameTable is used to speed up string comparison, there is nothing
done like "picking up namespace prefixes".
As said, with .NET 2.0 you have some way to use the XPathNavigator
itself, once moved to the proper node you want to "pick up namespace
prefixes" from, itself as the namespace manager.
<http://groups.google.c om/group/microsoft.publi c.dotnet.xml/msg/af7d7f9e2f422d7 e?hl=en&>
--
Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Craig Pearson |
last post by:
Hi
My function receives an XPathNavigator object. From here I need to build a
DataSet to load into SQL Server (using SQLXML adaptor). Does anyone have an
idea on the most efficient way to convert the XPathNavigator into a DataSet?
Here is what I have at the moment:
void function DoSomething( string xmlSchemeFile,
System.Xml.XPath.XPathNavigator nav ) {
|
by: Hollywood |
last post by:
I have the following code that is attempting to read nodes from an xml
file...
XmlDocument xpdStatus = new XmlDocument();
xpdStatus.Load("status.xml");
XPathNavigator xpnStatus = xpdStatus.CreateNavigator();
XPathNodeIterator xpniStatus = xpnStatus.Select("descendant::Status");
while (xpniStatus.MoveNext())
{
|
by: orange |
last post by:
Hello,
I have been trying to get data from an xml file with a namespace. I
have followed the example in the MSDN, but I get no data in t he
XPathNodeIterator, but the file has the data I am trying to extract.
...
XPathNavigator navigator = xmlDoc.CreateNavigator();
// xpathQuery = "/ProductInformation/ProductNumber"
XPathExpression expr = navigator.Compile( xpathQuery );
|
by: David Thielen |
last post by:
Hi;
Is there a way from an XPathNavigator object to get an xpath string that
will, when used in a Select(xpath) on the underlying base/root XPathNavigator
return the same XPathNavigator?
In other words, I initially create an XPathNavigator for my entire xml
document. To get an XPathNavigator object who's root is a given node in the
original xml document, there is a unique xpath that will return that node.
The unique xpath could have,...
|
by: David Thielen |
last post by:
Hi;
I have an element:
<space> </space>
When I call SelectSingleNode() on it, the InnerXml is a 0 length String, not
a String containing 1 space.
Any ideas?
| |
by: rdcpro |
last post by:
Hi all,
I've been building a nifty deserializing configuration handler that I use in
conjunction with my web.config in an ASP.NET web app. This is working quite
well, but I'm planning on servicing a number of different web service
operations from a single application, and because it's all XML, I've been
scoping everything to a specific namespace targeting a specific application
(these are all InfoPath forms).
It seems that the...
|
by: ericms |
last post by:
Can anybody show me how to insert a CDATA section using XPathNavigator ? I
have tried the follwing with no luck:
XmlDocument docNav = new XmlDocument();
docNav.LoadXml(xmlString);
XPathNavigator nav = docNav.CreateNavigator();
XmlDocument doc = new XmlDocument();
doc.LoadXml("<DocumentData></DocumentData>");
XmlElement elem = doc.CreateElement(currentNodeName);
|
by: Lou |
last post by:
I have been working on something very simple for days now argh!
In VB6 it was 4 lines of code in 5 minutes!
In VB .NET how do i parse this simple xml documenet.
I cant get a reference to any of the nodes.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <cap:alert xmlns:cap="http://www.incident.com/cap/1.0">
<cap:identifier>NOAA-NWS-ALERTS Alabama
2007-02-16T10:03:56-05:00</cap:identifier>...
|
by: Brent |
last post by:
I'm new to XML namespaces, and I seem to be missing something obvious
in this code snippet, which is trying to retrieve the feed/entry nodes
from an XPathNavigator document:
XmlNamespaceManager mgr = new
XmlNamespaceManager(xpNav.NameTable);
mgr.AddNamespace("atom", "http://www.w3.org/2005/Atom");
XPathExpression itemsExpr = xpNav.Compile("/atom:feed/
atom:entry/");
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |