473,661 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 XmlNamespaceMan ager, but when I do
something like:

nsmRequest.AddN amespace("ns1",
"http://localhost/ABC_ReturnAvail RS.xsd");
XmlNode node = xdHotels.Select SingleNode("//ns1:ABC_ReturnA vailRS.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_ReturnAvail RS.xsd
there is:

<xs:include schemaLocation= "ABC_CommonType s.xsd"/>

And in this file there is:

<xs:include schemaLocation= "ABC_SimpleType s.xsd"/>

So does this mean I have to add these to my XmlNamespaceMan ager
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 1424
The first param to SelectSingleNod e should be in xpath - just with prefixes
e.g. using your default namespace.

Consider the following:

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(doc.NameTa ble);
nsmgr.AddNamesp ace("x", doc.DocumentEle ment.GetAttribu te("xmlns"));
XmlElement el =
(XmlElement)doc .DocumentElemen t.SelectSingleN ode("x:Somethin g/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.AddN amespace("ns1",
"http://localhost/ABC_ReturnAvail RS.xsd");
XmlNode node =
xdHotels.Select SingleNode("//ns1:ABC_ReturnA vailRS.xsd", nsmRequest);

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

nsmRequest.AddN amespace("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.Select SingleNode("//ns1:nameofyourn ode",
nsmRequest);

May 23 '06 #4

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

Similar topics

1
1934
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 EmployeeManagement is a class library.
3
1788
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 projects within the same solution. We used identical namespace commands for both: "Level1.Level2.Level3" Both the C# and VB.NET classes live off "Level3." In other VB classes, I can do this... "Dim x as Level1.Level2.Level3.myVBClass"
3
6308
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 namespaces and lvl2 is used in lvl using the import feature lvl1.xsd -> lvl2.xsd
3
1923
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, 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
6
2074
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 DeviceManager which is only interested in CD/DVD devices. I want to get the list of CD/DVD devices and "be informed when a disc inserted into a device". I am developing this on Linux. So, I used HAL API and read some system (actually /proc) files to gather...
0
1210
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 enough, however all SDKs though incompatible use the NameSpace "MetaFrameCOM" so if I load more than one version of MFCom they overlap and Visual Studio reports ambiguous namespaces and to fully qualify things (well I can't because the namespace is
1
1989
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 load that assembly whose sub-classes are required to be loaded into the list box after pressing dot. for example in the code given below i have given the path of System.dll assembly file, now all the sub class of System.Data are automatically...
0
2266
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 multiple XmlSchema , i.e., via xs:import, to multiple output C# namespaces when using CodeDOM? Have no problem passing multiple schemas to XmlSchemaImporter and generating to single namespace, but this is pretty useless in any moderately complex...
1
2504
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 C# namespaces when using CodeDOM? Have no problem passing multiple schemas to XmlSchemaImporter and generating to single namespace, but this is pretty useless in any moderately complex enterprise where multiple assemblies are being shared which...
0
8428
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...
1
8542
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,...
1
6181
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
5650
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
4177
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...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
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
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
bsmnconsultancy
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...

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.