473,386 Members | 1,715 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,386 software developers and data experts.

XPath trouble - Help!

Any leads/help/ideas are greatly appreciated. I'm getting a response back
from a SOAP server and under classic ASP I was able to process the xml fine.

The app is being ported to c# and the same approach isn't working as well.
It fails at the xpath query after the results come back.

XML response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CheckResponse xmlns="http://local.domain.com">
<CheckResult>...

Code:
public int getBatchItemCount(XmlDocument oXML)
{
if (oXML != null)
{
XmlNamespaceManager nsmgr = new
XmlNamespaceManager(oXML.NameTable);
nsmgr.AddNamespace("xsd",
"http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace("soap",
"http://schemas.xmlsoap.org/soap/envelope/");
nsmgr.AddNamespace("xsi",
"http://www.w3.org/2001/XMLSchema-instance");

XmlNode oNode;
oNode =
oXML.DocumentElement.SelectSingleNode("//soap:Envelope/soap:Body/CheckRespon
se", nsmgr);
if (oNode == null)
{
return -999;
}
else
{
return oNode.ChildNodes.Count;
}
}
else
{
return 0;
}
}

The select always fails to return a result is I try to drill down past the
soap:Body as in the above. It's almost as if the different namespace listed
on the first element in the body is tripping it up. I tried adding
nsmgr.AddNamespace("", http://local.domain.com) but that didn't help either.

thanks,
jk
Nov 12 '05 #1
1 1365
Kirsplat wrote:
The select always fails to return a result is I try to drill down past the
soap:Body as in the above. It's almost as if the different namespace listed
on the first element in the body is tripping it up. I tried adding
nsmgr.AddNamespace("", http://local.domain.com) but that didn't help either.


nsmgr.AddNamespace("foo", "http://local.domain.com");

oXML.DocumentElement.SelectSingleNode("//soap:Envelope/soap:Body/foo:CheckResponse",
nsmgr);

PS. Wonder why? Read on XPath and default namespace.
--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2

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

Similar topics

1
by: P.Hill | last post by:
I'm using jaxen to pull a few things out of DOM tree and having trouble specifying an xPath. /mapping/to/from works fine, but /mapping/to doesn't. I'm sure it is something obvious. I try...
1
by: andy | last post by:
I am using XPath for the Electric XML Parser and having trouble getting simple XPath queries to work. The following query works: document.getElement(new...
2
by: Felicity | last post by:
Hello, The following XML file shows an example of some config data for a Side Button Bar control. There are two forms this Button Bar control relates to, "frmMainMenu" and "Listing". <?xml...
3
by: Shawn | last post by:
Hi. I have an XML file that looks like this: <?xml version="1.0" encoding="utf-16"?> <Transfer> <Config xmlns="http://www.mysite.com/Transfer/"> <site>NY</site> </Config> </Transfer> I'm...
2
by: Mark Fox | last post by:
Hello, I have some XML loaded into an XmlDocument and attempting to figure out how to access certain nodes. I assume I should use XPath, but I am having trouble getting the XPath syntax...
3
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0"...
3
by: Opa | last post by:
Hi, I have and XMLDataSource which I am using in a GridView control and am customizing the grid with <ItemTemplate>. My XML datasource has an element with an attribute called "private". I want...
5
by: tschulken | last post by:
I have a query where i need to look for a value of a lower level xml element based on the value of a parent element existing first. Here is a simple example of the xml <S3Client> <Buttons>...
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>
3
by: oopsatwork | last post by:
I'm trying to construct an XPath and it is giving me trouble. I have an XML that contains a "Routine". The routine contains "Steps". The steps have different types. Some types of steps have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
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
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...

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.