Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > XMLHTTPRequest with Xpath is not working

Thread Tools

XMLHTTPRequest with Xpath is not working

Posts: n/a

I am trying to call a web page to get xml response back using xmlWebRequest and HTTPWebResponse classes. After getting the response, I am loading it in to a xmlDocument for further processing. I am using XPath to verify and get results from XML Document.

Problem is, when I use the Xpath expression, eventhough document has value in it, it returns null object. When I checked the response using xml document's outerXML property, I found that each element has "\" charecters in front of it and "\ charecter at the end

Anybody has any idea of which kind of encoding should I use to eleiminate this problem?? Attaching code for reference

Thanks in advance for help.


Snippet =================
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(URL)
objRequest.Method = "POST"
objRequest.ContentLength = sRequest.Length
objRequest.ContentType = "application/x-www-form-urlencoded"

myWriter = new StreamWriter(objRequest.GetRequestStream())

catch (Exception e)

return null



HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse()
XmlTextReader xr = new XmlTextReader(objResponse.GetResponseStream());

//Validate XML content and get resul
XmlDocument xDoc =new XmlDocument(); //declare an XML document objec

xDoc.Load(xr); //load document with resul
xr.Close(); // Close and clean up the StreamReade

string sXPath="//Response/Status/StatusCode"
XmlNode xResult

XmlNamespaceManager xnm=new XmlNamespaceManager(xDoc.NameTable)

xResult = xDoc.SelectSingleNode(sXPath,xnm);//Query documen

if ((xResult!= null) && (xResult.InnerText.ToLower()=="0")) //here it fails to load valu

//process values of this documen

//XML I am getting
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><fiAPI xmlns=\"\" xmlnssi=\"\" xsi:schemaLocation=\"\"><fiHeader Version=\"\"><Service Version=\"\" Name=\"UserProfile\"><DateTime>2003-07-30T09:30:47-05:00</DateTime><UUID /></Service><Security><AuthenticationMaterial><Princip alPWD /><SignedToken>612d7b37614b39467264</SignedToken></AuthenticationMaterial><PrincipalID /></Security><Client Version=\"\"><VendorID /><AppID /><OrgID /><SessionID /></Client><DataSource><URI></URI></DataSource></fiHeader><Response TypeOfResponse=\"UserProfile\"><Status><StatusCode >0</StatusCode><Severity /></Status><UserProfile><IbList><IB ibCode=\"BHC\" ibName=\"\" /></IbList><OfficeList /></UserProfile><UserPrivileges><Privilege privName=\"EDOCUMENT\" privValue=\"Y\" context=\" Boolean\" />

//return xml is a big xml this is just a part for reference..

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath, XMLHttpRequest and parsing DOM Xandor Leahte Javascript 4 08-12-2011 03:59 PM
inline javascript not working while reading from XMLHttpRequest object Javascript 1 06-09-2006 02:35 PM
xmlhttprequest not working Javascript 4 09-21-2005 10:28 PM
XMLHttpRequest not working as expected Unknown User Javascript 2 02-08-2005 04:42 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM