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

Home Posts Topics Members FAQ

XPATH and Namespaces.

RK
Hi,

I'm calling a webservice that returns me data in a xml
node. However it has a specific namespace. I'm using the
xmlnamespacemanager, but the code does not work as
expected. Here is the code

oResponse.Data is the xmlnode returned by the webservice

Dim ns As System.Xml.XmlNamespaceManager = New
System.Xml.XmlNamespaceManager(New System.Xml.NameTable)
ns.AddNamespace("nm", oResponse.Data.NamespaceURI)
For Each oNode In oResponse.Data.SelectNodes
("/nm:Cg/nm:Cats/nm:Cat", ns)
Debug.WriteLine(oNode.Value)
Next

returns nothing

The xpath seems to be valid as the same works in
xselerator with the same prefix added to the namespaces in
the tool.

Also if I go to the debug pane and type
?ns.LookupPrefix(ns.NameTable.Get("nm"))
or
?ns.LookupPrefix("nm")
or
?ns.LookupNamespace(ns.NameTable.Get("nm"))
or
?ns.LookupNamespace("nm")
it only return 'nothing'.
I also tried the same by calling the addnamespace in debug
window with different prefix and uri with the same result.

I'm missing some crucial piece here, but can't place it.
Any help is appreciated.

TIA
RK.
Nov 12 '05 #1
4 1549
RK wrote:
I'm calling a webservice that returns me data in a xml
node. However it has a specific namespace. I'm using the
xmlnamespacemanager, but the code does not work as
expected. Here is the code

oResponse.Data is the xmlnode returned by the webservice

Dim ns As System.Xml.XmlNamespaceManager = New
System.Xml.XmlNamespaceManager(New System.Xml.NameTable)
ns.AddNamespace("nm", oResponse.Data.NamespaceURI)

This line looks suspicious to me. What kind of node oResponse.Data is?
In order to get NamespaceURI it must be either XmlElement or
XmlAttribute. For other types of nodes it's empty string, say if
oResponse.Data is XmlDocument. If so, try
oResponse.Data.DocumentElement.NamespaceURI
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
RK
Oleg, the class was created by the code generator when I
added a web reference. I'm not sure if its an element or
a document. However, I know that the URI has the correct
value as I can check that out in the watch window/debug
window.
-RK.
-----Original Message-----
RK wrote:
I'm calling a webservice that returns me data in a xml
node. However it has a specific namespace. I'm using the xmlnamespacemanager, but the code does not work as
expected. Here is the code

oResponse.Data is the xmlnode returned by the webservice

Dim ns As System.Xml.XmlNamespaceManager = New
System.Xml.XmlNamespaceManager(New System.Xml.NameTable)
ns.AddNamespace("nm", oResponse.Data.NamespaceURI)This line looks suspicious to me. What kind of node

oResponse.Data is?In order to get NamespaceURI it must be either XmlElement orXmlAttribute. For other types of nodes it's empty string, say ifoResponse.Data is XmlDocument. If so, try
oResponse.Data.DocumentElement.NamespaceURI
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

.

Nov 12 '05 #3
RK wrote:
Oleg, the class was created by the code generator when I
added a web reference. I'm not sure if its an element or
a document.

Hmm, how can you select something being not sure what is input data?
Use oResponse.Data.WriteTo(new XmlTextWriter("dump.xml")) to show us the
data you are trying to query.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #4
RK
Oleg,

I found that my XPath was not correct

/nm:Cg/nm:Cats/nm:Cat does not work
but
/nm:Cats/nm:Cat works.

Thanks.
-----Original Message-----
RK wrote:
Oleg, the class was created by the code generator when I added a web reference. I'm not sure if its an element or a document.Hmm, how can you select something being not sure what is

input data?Use oResponse.Data.WriteTo(new XmlTextWriter("dump.xml")) to show us thedata you are trying to query.
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

.

Nov 12 '05 #5

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

Similar topics

2
by: Piet | last post by:
Hello, Via Xpath, I want to access nodes which have a namespace prefix. THe document at hand is an Xsl-FO document. I tried the following: from xml.dom import minidom from xml.xpath import...
3
by: Colin Green | last post by:
I have come across what seems like a failing in the .Net XML classes. Many people have posted requesting how to write an XPath query with namespace prefixes that works. The solution shown in all...
1
by: Hollywood | last post by:
I have the following XSD created in VS.NET 2003: <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="ReferralSchama" targetNamespace="http://test.org/Referral"...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
6
by: AMDRIT | last post by:
Hello Everyone, I am having an issue with xml and namespaces, at least I think it is namespaces. When I use namespaces, I cannot use SelectSingleNode / SelectNodes as they always return...
14
by: Mat| | last post by:
Hello :-) I am learning XPath, and I am trying to get child nodes of a node whose names do *not* match a given string, e.g : <dummy> <example> <title>Example 1</title> <body>this is an...
6
by: J.Marsch | last post by:
I must be completely losing my mind. I have some code that writes to config files. It works great with app.config files, but fails miserably with web.config files. For the life of me, I cannot...
14
by: Mikhail Teterin | last post by:
Hello! What's would be the syntax for a query, which would allow me to get only the elements with non-empty text-nodes? For example, from: <a><b></b></a> <c/> <d><e>meow</e></d>
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
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...
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
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 ...
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.