473,395 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Working with multiple namespaces

Hi Everyone

I was wondering if anyone knew of a good guide to working with multiple
namespaces under .NET? And also help me with my latest poser.

As you may have calculated by my other posts, I am working under a lot
of new technologies that I didn't realise I would be when I took the
job - so I am on a steep learning curve (too steep at times!!! lol).

Very basically, I want to be able to do some XPath on XML I am getting
back from a web-service, and I have worked out that I need to apply my
DTDs because there is an xmlns attribute in my root element.

<Root Target="test" Version="2002A"
xmlns="http://www.testurl.com/abc/2002/09">

I have seen how to do this with an XmlNamespaceManager, but when I do
something like:

nsmRequest.AddNamespace("ns1",
"http://localhost/ABC_ReturnAvailRS.xsd");
XmlNode node = xdHotels.SelectSingleNode("//ns1:ABC_ReturnAvailRS.xsd",
nsmRequest);

I just get a null value.

I have 'invented' that prefix because I cannot see a named prefix in my
xsd - but I have also tried String.Empty() and get null back.

The one thing I may be doing wrong is that in my ABC_ReturnAvailRS.xsd
there is:

<xs:include schemaLocation="ABC_CommonTypes.xsd"/>

And in this file there is:

<xs:include schemaLocation="ABC_SimpleTypes.xsd"/>

So does this mean I have to add these to my XmlNamespaceManager
instance? And what do I do about giving each namespace a named
instance?

Hopefully I have made some sense here - and as ever I thank you for
taking the time to cast your eye over this for me.

Many many thanks

Best regards

Darren

May 23 '06 #1
3 1408
The first param to SelectSingleNode should be in xpath - just with prefixes
e.g. using your default namespace.

Consider the following:

XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("x", doc.DocumentElement.GetAttribute("xmlns"));
XmlElement el =
(XmlElement)doc.DocumentElement.SelectSingleNode(" x:Something/x:SomethingElse",
nsmgr);

This creates a new manager (using the existing name table), adds "x" as the
default namespace (reading from the document element), then queries
Something/SomethingElse in this namespace.

Hope this helps,

Marc
May 23 '06 #2
Marc

What is the NameTable - because currently although this is in my
declaration, I'm not actually doing anything with it.

Do I need to do doc.Schemas.Add(...) for the specified xsd's as I
mentioned above?

Many thanks

Darren

May 23 '06 #3
I got to the bottom of it Mark - it cost me 500 points on experts
exchange, but I'm not complaining.... I had the Namespace named
incorrectly

[QUTOTE]

This line looks wrong:

nsmRequest.AddNamespace("ns1",
"http://localhost/ABC_ReturnAvailRS.xsd");
XmlNode node =
xdHotels.SelectSingleNode("//ns1:ABC_ReturnAvailRS.xsd", nsmRequest);

The namespace in your Root node is "http://www.testurl.com/abc/2002/09"
not "ABC_ReturnAvailRS.xsd". So, when adding it to the namespace
manager it should look like:

nsmRequest.AddNamespace("ns1",
"http://www.testurl.com/abc/2002/09");

You then specify "ns1" as the prefix when searching for nodes in the
XML:

XmlNode node = xdHotels.SelectSingleNode("//ns1:nameofyournode",
nsmRequest);

May 23 '06 #4

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

Similar topics

1
by: DKode | last post by:
I have 2 projects in a solution: Web EmployeeManagement The namespace for Web is : CompanyName.Hybrid.Web The namespace for EmployeeManagement is just : CompanyName.Hybrid ...
3
by: Tom Kelleher | last post by:
Question: Can namespaces be shared by several projects within a solution, if those projects use different languages? We wrote some db code in C#, and some biz logic in VB.NET. We brought both...
3
by: John Smith | last post by:
Ok, I am not sure if it is possible. But what I'm trying to do is validate an XML file with out having to add namespace in the xml. What I mean is lets say I have 2 XSD they have different...
3
by: daz_oldham | last post by:
Hi Everyone I was wondering if anyone knew of a good guide to working with multiple namespaces under .NET? And also help me with my latest poser. As you may have calculated by my other posts,...
6
by: Orgun | last post by:
Hi, I sent this message to the moderated c++ group too but it is waiting for moderator approval and I wanted to send here too. I am new to Design Patterns. I want to write a simple...
0
by: Dave | last post by:
Hello all, Firstly I hate Citrix, especially their programming interface MFCOM. There are multiple versions, that seem to need to match an SDK Version <----Citrix Server Version This is bad...
1
by: icfai | last post by:
hi friends.... I have got a problem regarding loading of multiple assemblies, actually its required for an editor which implements the intellisenseas in vb or dotnet. for that it is required to...
0
by: =?Utf-8?B?Q2FtZWw=?= | last post by:
For anyone who has utilised classes under XSD.exe and CodeDOM (please redirect me to another group perhaps if not here) please any ideas on how to translate the multiple namespaces present within...
1
camel
by: camel | last post by:
For anyone who has utilised classes under XSD.exe and CodeDOM, please any ideas on how to translate the multiple namespaces present within multiple XmlSchema , i.e., via xs:import, to multiple output...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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,...

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.