473,473 Members | 1,837 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SelectSingleNode and Namespace

Hi,

I use a XML-Doc with a Namespace like the following example:

<HomedResources xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3">

<HomedResource UserAtHost="PB***@team.de" Enabled="1" VersionPermission="10"

VersionContact="25" DisplayName="Boullay, Peter" Email="PB***@team.de" Phone="+88

09 75" LastRegisterTime="2005-03-29T09:36:00"

xmlns="http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">

<ContactGroups>

<ContactGroup Number="1" DisplayName="~">

</ContactGroup>

</ContactGroups>

.........

When I then use

Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)

Dim node As XmlNode

xmlDoc.Load(pfad)

Dim nodeX As XmlNode = xmlDoc.SelectSingleNode("/HomedResources", xmlNsM)

The SelectSingleNode Method doesn't find any node!

But when I remove the xmlns-Attribute on the top of the XML-Document SelectSingle Node find a node.

Any Idea how to use SelectSingleNode with Namespaces?

thanx

Marcel

Nov 12 '05 #1
3 3284
I haven't tried out the code but I have noticed that you didn't place the
namespace between quotes.

Gabriel Lozano-Morán

"Jonathan" <Jo******@weissnichwo.com> wrote in message
news:#h*************@TK2MSFTNGP12.phx.gbl...
Hi,

I use a XML-Doc with a Namespace like the following example:

<HomedResources
xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3">
<HomedResource UserAtHost="PB***@team.de" Enabled="1"
VersionPermission="10"
VersionContact="25" DisplayName="Boullay, Peter"
Email="PB***@team.de" Phone="+88
09 75" LastRegisterTime="2005-03-29T09:36:00"
xmlns="http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">
<ContactGroups>
<ContactGroup Number="1" DisplayName="~">
</ContactGroup>
</ContactGroups>
.........

When I then use

Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)
Dim node As XmlNode
xmlDoc.Load(pfad)
Dim nodeX As XmlNode = xmlDoc.SelectSingleNode("/HomedResources",
xmlNsM)

The SelectSingleNode Method doesn't find any node!

But when I remove the xmlns-Attribute on the top of the XML-Document
SelectSingle Node find a node.

Any Idea how to use SelectSingleNode with Namespaces?

thanx

Marcel
Nov 12 '05 #2


Jonathan wrote:

I use a XML-Doc with a Namespace like the following example:
<HomedResources
xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3">

<HomedResource UserAtHost="PB***@team.de" Enabled="1"
VersionPermission="10"

VersionContact="25" DisplayName="Boullay, Peter"
Email="PB***@team.de" Phone="+88

09 75" LastRegisterTime="2005-03-29T09:36:00"

xmlns="http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">

<ContactGroups>

<ContactGroup Number="1" DisplayName="~">

</ContactGroup>

</ContactGroups>

........

When I then use

Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)

Dim node As XmlNode

xmlDoc.Load(pfad)

Dim nodeX As XmlNode =
xmlDoc.SelectSingleNode("/HomedResources", xmlNsM)

The SelectSingleNode Method doesn't find any node!

But when I remove the xmlns-Attribute on the top of the XML-Document
SelectSingle Node find a node.

Any Idea how to use SelectSingleNode with Namespaces?


Within XPath 1.0 you always need to bind a prefix to a namespace URI to
select elements in a certain namespace:
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/616>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #3
You need to have a "dummy" prefix associated with that namespace.
xmlNsM.AddNamespace("default",
"http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp");

Then use that prefix with your XPath queries:
Dim nodeX As XmlNode = xmlDoc.SelectSingleNode("/default:HomedResources",
xmlNsM)

PS
"default" is just a name, it could have been anything.

--
Regards,
Dennis JD Myrén
Oslo Kodebureau
"Jonathan" <Jo******@weissnichwo.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Hi,

I use a XML-Doc with a Namespace like the following example:

<HomedResources
xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3">
<HomedResource UserAtHost="PB***@team.de" Enabled="1"
VersionPermission="10"
VersionContact="25" DisplayName="Boullay, Peter"
Email="PB***@team.de" Phone="+88
09 75" LastRegisterTime="2005-03-29T09:36:00"
xmlns="http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp">
<ContactGroups>
<ContactGroup Number="1" DisplayName="~">
</ContactGroup>
</ContactGroups>
.........

When I then use

Public xmlNsM As New XmlNamespaceManager(xmlDoc.NameTable)
Dim node As XmlNode
xmlDoc.Load(pfad)
Dim nodeX As XmlNode = xmlDoc.SelectSingleNode("/HomedResources",
xmlNsM)

The SelectSingleNode Method doesn't find any node!

But when I remove the xmlns-Attribute on the top of the XML-Document
SelectSingle Node find a node.

Any Idea how to use SelectSingleNode with Namespaces?

thanx

Marcel
Nov 12 '05 #4

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

Similar topics

2
by: Edward Yang | last post by:
My XML document has a default namespace specified by xmlns="some_url". Here it is: <?xml version="1.0" encoding="utf-8" ?> <ssmproject name="sample" server="sql"...
7
by: Jason | last post by:
Hi I have an XML file i need to load and read the contents. Here is the top part of the xml file. <Research xsi:schemaLocation="http://www.rixml.org/2002/6/RIXML...
2
by: adam | last post by:
I tried so many ways to select the node but its not working, please help. I want to research by the identifier in imsmanifest.xml file, the node could be item or resource. XmlDocument doc = new...
6
by: David Thielen | last post by:
Hi; I am calling SelectSingleNode("/xml/s:Schema/s:ElementType/@name") where "/xml/s:Schema/s:ElementType/@name is a legit xpath statement (xml is the name of the rootnode) and that xpath...
1
by: Angela | last post by:
I am getting an error when I attempt to access a node with SelectSingleNode(): "The expression passed to this method should result in a NodeSet." I understand there is some confusion when you have...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
0
by: Martin | last post by:
Hi, I am using xmldocument.selectsinglenode to query an xml document. This works perfectly when the document to be queried has no namespace, however as some as i put a namespace in then null is...
1
by: Henry Padilla | last post by:
I'm sorry if this has been asked and answered, I looked and didn't find this particular situation so I have to ask. If I understand correctly, the .NET XMLDOM must have an XmlNamespaceManager...
3
by: =?Utf-8?B?bmVlZDJzY3ViYQ==?= | last post by:
I have the following code snipet: .... _xmldocManifest.Load(strManifestAbsolutePath) Dim manifestNSManager As XmlNamespaceManager = New XmlNamespaceManager(_xmldocManifest.NameTable)...
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,...
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
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: 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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.