473,804 Members | 3,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlNamespaceMan ager, 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 ----

<Configuratio n
xmlns="urn:serv er:schemas:conf iguration"
xmlns:f="urn:se rver:schemas:fa q">
<version version="0.0.00 01">
<f:faq>
<f:section>Defa ult</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");
XmlNamespaceMan ager xnm = new XmlNamespaceMan ager(xd.NameTab le);
xnm.AddNamespac e(String.Empty, "urn:server:sch emas:configurat ion");
xnm.AddNamespac e("f", "urn:server:sch emas:faq"); // faq container namespace
XmlNode xnFaq = xd.SelectSingle Node(

"/Configuration/version[@version=\"0.0. 0001\"]/f:faq[f:section=\"Def ault\"]"
, xnm);

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

xnm.AddNamespac e("c", "urn:server:sch emas:configurat ion");
xnm.AddNamespac e("f", "urn:server:sch emas:faq"); // faq container namespace
XmlNode xnFaq = xd.SelectSingle Node(

"/c:Configuration/c:version[@c:version=\"0. 0.0001\"]/f:faq[f:section=\"Def au
lt\"]", xnm);

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

- Oisin

Nov 11 '05 #1
3 8142

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

XmlNode xnFaq = xd.SelectSingle Node(

"/Configuration/version[@version='0.0.0 001']/f:faq[f:section='Defa ult']"
, 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******** ******@TK2MSFTN GP11.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.0 001']/f:faq[f:section='Defa ult']"
, xnm);
"Oisin Grehan" <oi****@nospam. iol.ie.> wrote in message
news:#K******** ******@TK2MSFTN GP10.phx.gbl...

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

XmlNode xnFaq = xd.SelectSingle Node(

"/Configuration/version[@version='0.0.0 001']/f:faq[f:section='Defa ult']"
, 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
2725
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 namespace prefix, what is its namespace, if default namespaces do not apply? Are (either of) prefixed or non-prefixed attributes correct? For example, are the following equivalent: <html:br class="foo"...
6
2595
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 schema for it with Visual Studio, I get the error "Failed to create a schema for this data file because:
9
9028
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 namespace from the XML data, the query worked. Okay, so I added code to create a XMLNamespaceManager and populate it with the namespace. Now, I'm getting this exception: Prefixes beginning with "xml" (regardless of whether the characters...
5
2409
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 XmlNamespaceManager(xml.NameTable); context.AddNamespace("", "http://www.test.org"); context.AddNamespace("sns", "http://www.test.org/sub"); XmlNode node = xml.SelectSingleNode("/root", context);
7
1439
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 unable to access the class from the first without qualifying it, which is what i want to avoid. Any ideas what I am doing wrong? I am attaching the code and compiler error below to show exactly what I am trying to do,
3
2324
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. NameSpaces and Java Packages are similar in nature? In the dot net world, you are not able to pick out (import) a particulare "class" within the namespace - just the entire namespace. Is that Right? In Java, I would carve out a place on my...
17
2079
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 write a signature for the developer and after getting a good start developing a 2.0 application I thought I should go through the code and start marking classes and with namespaces. I keep getting the following 'missing' error even when using a first...
7
1845
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 essentially following up to my last post so apologies for repeating parts of the post. The transformation stylesheet is (after corrections from kind contributors :) <?xml version="1.0" encoding="UTF-8"?>
0
2428
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 www.geocaching.com. - The file contains a bunch of elements called <WPT> - Within the WPT elements are a number of other elements <time>, <sym>, <groundspeak:name>... - The non-qualified elements come from a schema/namespace at...
0
9706
marktang
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...
0
9579
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,...
0
10326
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 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...
1
10317
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,...
0
9143
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
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...
2
3815
muto222
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.