473,399 Members | 2,159 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,399 software developers and data experts.

Need to retrieve nodes from xml page.

Hi all,

I'm having this problem, the following code is used to request a page
where I want to be able to read the response, which is an xml page:
string sUrl = "http://www.thirdpartysendingsms.com";
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create(sUrl);
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());
string sResponse = sr.ReadToEnd();
sResponse contains: bostaddirekt97579

While the whole page I've requested looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
- <response code="0" description="Message processed">
<error code="3" description="Could not find any matching prefix for
+99999">bostaddirekt97579</error>
</response>
Now what I want is to be able to extract the error code, in Java I see
them using something like:
URL myUrl = new URL(sUrl);
HttpURLConnection myConn = (HttpURLConnection) myUrl.openConnection();
InputStream in = myConn.getInputStream();
Document myResponse = documentBuilder.parse(in);
Element root = myResponse.getDocumentElement();
And then from there one works with the root to find a specific node, is

there anything equivalent in c#?
Thanks for any pointers!

Dec 19 '06 #1
2 2388
Niclas Colleen wrote:
Hi all,

I'm having this problem, the following code is used to request a page
where I want to be able to read the response, which is an xml page:
string sUrl = "http://www.thirdpartysendingsms.com";
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create(sUrl);
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());
string sResponse = sr.ReadToEnd();
sResponse contains: bostaddirekt97579

While the whole page I've requested looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
- <response code="0" description="Message processed">
<error code="3" description="Could not find any matching prefix for
+99999">bostaddirekt97579</error>
</response>
Now what I want is to be able to extract the error code, in Java I see
them using something like:
URL myUrl = new URL(sUrl);
HttpURLConnection myConn = (HttpURLConnection) myUrl.openConnection();
InputStream in = myConn.getInputStream();
Document myResponse = documentBuilder.parse(in);
Element root = myResponse.getDocumentElement();
And then from there one works with the root to find a specific node, is

there anything equivalent in c#?
Thanks for any pointers!
Check out system.xml. There are a whole set of classes to read/write xml
document. You probably want to look for something like XmlReader..
Dec 19 '06 #2
Thanks Jianwei, This was exactly what I was looking for, I'll post my
code below:

//Request page
HttpWebRequest Req =(HttpWebRequest)WebRequest.Create(sURL);
WebResponse Res = Req.GetResponse();
XmlTextReader xReader = new XmlTextReader(Res.GetResponseStream());

//Examine return code
while(xReader.Read())
{
if(xReader.Name == "error")
{
//Error!!!
}
}
Jianwei Sun skrev:
Niclas Colleen wrote:
Hi all,

I'm having this problem, the following code is used to request a page
where I want to be able to read the response, which is an xml page:
string sUrl = "http://www.thirdpartysendingsms.com";
HttpWebRequest myRequest =(HttpWebRequest)WebRequest.Create(sUrl);
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream());
string sResponse = sr.ReadToEnd();
sResponse contains: bostaddirekt97579

While the whole page I've requested looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
- <response code="0" description="Message processed">
<error code="3" description="Could not find any matching prefix for
+99999">bostaddirekt97579</error>
</response>
Now what I want is to be able to extract the error code, in Java I see
them using something like:
URL myUrl = new URL(sUrl);
HttpURLConnection myConn = (HttpURLConnection) myUrl.openConnection();
InputStream in = myConn.getInputStream();
Document myResponse = documentBuilder.parse(in);
Element root = myResponse.getDocumentElement();
And then from there one works with the root to find a specific node, is

there anything equivalent in c#?
Thanks for any pointers!

Check out system.xml. There are a whole set of classes to read/write xml
document. You probably want to look for something like XmlReader..
Dec 20 '06 #3

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

Similar topics

1
by: Scott Simpson | last post by:
I can build portions of DOM trees with jdom and xpathapi and using "new Element()" and "appendChild()" or "addContent()". Which function do I use to get a whole portion of a DOM tree though? For...
2
by: LoserInYourFaceEngineer | last post by:
Hello All: I'm having trouble with a recursive function. The function is supposed to identify nested folders in a hierarchical folder structure. The function "searchForFolders()" is...
2
by: Cali | last post by:
Please bear with me, I have been reading about XSL for a couple hours. I have an XML document that contains multiple <page> tags interspersed throughout the tree. <text> .... <page>1</page>...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
7
by: David | last post by:
I have a xml file: <OrderDetail TotalCount="2"> <ProductLine> <LineNumber>1</LineNumber> <ProductNumber>A001</ProductNumber> <ProductDescription>17"VP171b</ProductDescription>...
7
by: tman | last post by:
I am generating a very large tree list in my program and while it's performance is great once loaded it takes a really long time to load. I create a root TreeNode "offline" and go through the...
1
by: san1014 | last post by:
Hi I have a table SQL> select * from nodes; NODE_ID NODE_NAME -------------------- ------------------------------ N1 Kothhapet N2 Nagole...
1
by: Falcula | last post by:
Hello, I have a treeview control, when i select a item i navigate to url. But selected node is lost, it reset itself, loosing state. I post my code here. Thanks in advance. <script...
0
by: empiresolutions | last post by:
Howdy, I have an PHP page that edits XML files. I want ADD a new *id* attribute to all nodes on the page that do not have it all ready. Then i want to delete all of the values of *id* and set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
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
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...

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.