473,765 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C#-XPath - Help with XPath Query and SOAP Response

2 New Member
Hello,

I have a C# application that is consuming a C# WebService. I am calling a method on the WebService and it is sending me back a response which contains an XmlDocument:
Expand|Select|Wrap|Line Numbers
  1. string soapMessage = "<?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><validateStudent xmlns=\"http://tempuri.org/StudentResults/\"><studentID>" + txtStudentID.Text + "</studentID></validateStudent></soap:Body></soap:Envelope>";
  2. HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/StudentResults/Results.asmx");
  3. XmlDocument doc = new XmlDocument();
  4.  
  5. doc.LoadXml(soapMessage);
  6.  
  7. req.ContentType = "text/xml; charset=utf-8";
  8. req.Accept = "text/xml";
  9. req.Method = "POST";
  10. req.Headers.Add("SOAPAction", @"http://tempuri.org/StudentResults/validateStudent");
  11. Stream stm = req.GetRequestStream();
  12. doc.Save(stm);
  13. stm.Close();
  14. WebResponse resp = req.GetResponse();
  15. stm = resp.GetResponseStream();
  16. StreamReader r = new StreamReader(stm);
  17.  
  18. XmlDocument response = new XmlDocument();
  19. response.LoadXml(r.ReadToEnd());
  20.  
Problem I have is that the Stream response
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8"?>
  2.   <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">
  3.     <soap:Body>
  4.       <validateStudentResponse xmlns="http://tempuri.org/StudentResults/">
  5.         <validateStudentResult>
  6.           <validateStudent xmlns="">
  7.             <studentID>1234</studentID>
  8.             <studentName>Andrew Harris</studentName>
  9.           </validateStudent>
  10.         </validateStudentResult>
  11.       </validateStudentResponse>
  12.     </soap:Body>
  13. </soap:Envelope>
contains the SOAP envelope and I cant get the following XPath Query to return the relevant Node, the "name" XmlNode is always "Undefined" ?

Expand|Select|Wrap|Line Numbers
  1. XmlNamespaceManager nsm = new XmlNamespaceManager(response.NameTable);
  2. nsm.AddNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/");
  3. nsm.AddNamespace("sr","http://tempuri.org/StudentResults/");
  4.  
  5. XmlNode currentNode = response.DocumentElement.FirstChild;
  6. XmlNode name = currentNode.SelectSingleNode("/soap:Envelope/soap:Body/sr:validateStudentResponse/validateStudentResult/validateStudent/studentID", nsm);
Any help appreciated.

Regards

Andrew
May 13 '07 #1
2 7303
hary
2 New Member
Anyone able to help?
May 14 '07 #2
kenobewan
4,871 Recognized Expert Specialist
Have you tried stripping the soap envelope?
May 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4020
by: John Barring | last post by:
Hi All, I am new to XPath stuff. I want parse XMLDocument with XPath and find out subset of information. If you look at following xml, for i.e how can i retrieve subset information such as 'EnrollmentState','SCGProductCollection' or 'EnrollmentEntities'. I have no idea how to parse following XML <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1
1139
by: jeffreyv | last post by:
Hi! Here's a XML reprensenting a company. I would like to make a XPath query that gives me all the employees that are Programmer or Analyst and have 5 years of experience. I did the following query "//*/*//parent::*/*//parent::*" and it gives me 4 nodes. The 2 I need and one for Position and another for YearsOfExperience.
2
1135
by: mel_dev | last post by:
All, I'm brand new to XML and have been given a deadline to deliver some new functionality part of which requires stepping through an xml doc. I have hit a wall with the way I've structured an xpath query to select nodes from the xml and would be most appreciative of some assistance. The beginning of the xml doc looks like this: <?xml version="1.0" encoding="UTF-8"?> <ClliOutput xmlns="http://hobb.catalina.telcordia.com"
4
7850
by: Christian Wilhelm | last post by:
Hi! I have a Problem understanding the deserialisation of SOAP-Responses. The "normal" way, calling a XML WebService is to use WSDL 1) Send Request 2) Get SOAP-Response 3) With Informations out of WSDL transform the SOAP-Response to an Object. Let us call it "Customer".
3
4136
by: 0to60 | last post by:
Please help! I'm using the following code to get an XML doc: string str = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=12345&city=addison"; System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(str); request.Credentials = System.Net.CredentialCache.DefaultCredentials;
1
2667
by: Gregor D. | last post by:
Hi, I want to consume an Apache Webservice with a C# .NET Client. Everything works fine, but I'm having problem with the deserialization of the complex type "Item" that is included in the response of the web service, what seems so be the type "hashtable" in .NET. Every "Item" consists of two fields "key" and "value". I read a lot about SOAP/Apache/.NET/Complex Types/etc. and somewhere I read that there is no automatic deserialization...
2
1557
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am trying to construct an XPath query against an XML document, for a requirement that I have. Below is the XML fragment: <SUBMISSIONS> <SUBMISSION YEAR="2004"> <MONTH NAME="JAN">10</MONTH> <MONTH NAME="FEB">02</MONTH>
5
2436
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> <Button>Activity <RestrictedClientType> <ClientType>02</ClientType> </RestrictedClientType>
3
1007
by: rajasekharsiva | last post by:
hi all, i am new to .net i have problem i have an xml fille lik this::: <?xml version="1.0" encoding="utf-8"?> <personal_info> <personal_id ID="1"> <name first_name="rajasekhar" middle_name="siva" last_name="aluru" nick_name="sekhar" /> <gender value="Male" /> <group group_name="bestfriends" parent_group="Friends" />
0
9398
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
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,...
0
9832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7378
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
6649
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
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
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

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.