473,473 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XmlNamespaceManager, default namespaces, nested qualified namespace, xpath problem.

Hi,
I can't for the life of me get this to work properly. I've searched for
examples, but none of the examples quite match my environment. Here is my
XML (please treat this as immutable -- no solutions involving altering the
XML are good for me):

---- config.xml ----

<Configuration
xmlns="urn:server:schemas:configuration"
xmlns:f="urn:server:schemas:faq">
<version version="0.0.0001">
<f:faq>
<f:section>Default</f:section>
<f:item>
<f:q>What is the meaning of life?</f:q>
<f:a>42.</f:a>
</f:item>
</f:faq>
</version>
</Configuration>

I want to have an XmlNode object referencing the first <faq> tag. Here is
the corresponding c# code:

XmlDocument xd = new XmlDocument();
xd.Load("config.xml");
XmlNamespaceManager xnm = new XmlNamespaceManager(xd.NameTable);
xnm.AddNamespace(String.Empty, "urn:server:schemas:configuration");
xnm.AddNamespace("f", "urn:server:schemas:faq"); // faq container namespace
XmlNode xnFaq = xd.SelectSingleNode(

"/Configuration/version[@version=\"0.0.0001\"]/f:faq[f:section=\"Default\"]"
, xnm);

This fails to select the f:faq node. I've tried using the following also:

xnm.AddNamespace("c", "urn:server:schemas:configuration");
xnm.AddNamespace("f", "urn:server:schemas:faq"); // faq container namespace
XmlNode xnFaq = xd.SelectSingleNode(

"/c:Configuration/c:version[@c:version=\"0.0.0001\"]/f:faq[f:section=\"Defau
lt\"]", xnm);

I'm beginning to lose the mind here people; any ideas? Cheers!

- Oisin

Nov 11 '05 #1
3 8111

"Steven Livingstone" <s.***********@nospam.btinternet.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Have you tried this?

XmlNode xnFaq = xd.SelectSingleNode(

"/Configuration/version[@version='0.0.0001']/f:faq[f:section='Default']"
, xnm);

?


Nope, that's not it. If I strip the default namespace declaration out of the
xml, e.g. the root tag is just <Configuration>, everything works fine. But
like I mentioned, this is not an option for me. Thanks for the try anyway.

- Oisin

Nov 11 '05 #2
Right -- for the benefit of the rest of the group, the problem was in the
XPath query;

if should have been:

/c:Configuration/c:version[@version=\"0.0.0001\"] ...

instead of

/c:Configuration/c:version[@c:version=\"0.0.0001\"] ...

I was qualifying the attribute with a namespace prefix and I didn't need to.
Guess I'd better read up a little more on schema defaults :)

- Oisin

"Oisin Grehan" <oi****@nospam.iol.ie.> wrote in message
news:eE**************@TK2MSFTNGP11.phx.gbl...
Hi,


<snip />
Nov 11 '05 #3
ok, with the c prefix try.. (sorry not to take more time but i'm rushed of
my feet for the next couple of hours!)

"/c:Configuration/c:version[@version='0.0.0001']/f:faq[f:section='Default']"
, xnm);
"Oisin Grehan" <oi****@nospam.iol.ie.> wrote in message
news:#K**************@TK2MSFTNGP10.phx.gbl...

"Steven Livingstone" <s.***********@nospam.btinternet.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
Have you tried this?

XmlNode xnFaq = xd.SelectSingleNode(

"/Configuration/version[@version='0.0.0001']/f:faq[f:section='Default']"
, xnm);

?
Nope, that's not it. If I strip the default namespace declaration out of

the xml, e.g. the root tag is just <Configuration>, everything works fine. But
like I mentioned, this is not an option for me. Thanks for the try anyway.

- Oisin


Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John L. Clark | last post by:
I am curious as to the rationale, and effect, of having default namespaces not applying (directly) to attributes (see http://www.w3.org/TR/REC-xml-names/#defaulting). Given an attribute without a...
6
by: Martin | last post by:
Hi, I have a xml file like the one below <?xml version="1.0" encoding="utf-8"?><e1 xmlns:e1="http://tempuri.org/Source1.xsd" e1:att1="1" e1:att2="2" e1:rest="345"/> If I try to create a...
9
by: Richard L Rosenheim | last post by:
I'm trying to query a XML file that was created via ADO.NET. My query wasn't returning anything, and I tracked the problem to an issue with the namespace that ADO.NET specified. When I remove the...
5
by: David Thielen | last post by:
Hi; I set up my xml as follows: XmlDocument xml = new XmlDocument(); xml.Load(File.Open("data.xml", FileMode.Open, FileAccess.Read)); XmlNamespaceManager context = new...
7
by: Aniket Sule | last post by:
Hi, I am trying to use a class from one namespace in another via the using directive. The 2 namespaces have some part of the name in common (A.B.x, A.B.y). However in the second namespace, I am...
3
by: Jim Heavey | last post by:
Trying to get the hang of Namespaces. I have primarly developed in VB and am transitioning to C# and the .Net Environment. I have worked a bit with Java as well in school about a year or so ago....
17
by: clintonG | last post by:
Using 2.0 with Master Pages and a GlobalBaseClass for the content pages. I understand the easy part -- the hierarchical structure of a namespace naming convention -- but the 2.0 IDE does not...
7
by: Bilal | last post by:
Hello all, I came across this problem while working out the bugs in my identity trasnformation stylesheets but sidestepped it for later to see if there is an easier/better solution. This is...
0
by: davsmith_shop | last post by:
Hopefully I can ask this question without regaling you kind people in too many gory details. Here's what I'm trying to do: - I have a local XML file with a .GPX extension which I downloaded from...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
1
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...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.