Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have below url need to read xml values from the url
192.185.0.25:8080/red/info

What I have tried:

WebClient wc = new WebClient();
			var method = "POST";
			wc.Headers.Add(URLAUTH);
			wc.Headers.Add("Content-type","application/x-www-form-urlencoded");					
			NameValueCollection collection = new NameValueCollection();		
			collection.Add("id", "0");
		    collection.Add("sno", "1");	
	byte[] bret = wc.UploadValues(URLAUTH,method,collection);
			sret = System.Text.Encoding.Default.GetString(bret);
Posted
Updated 28-Jun-18 20:10pm
Comments
Maciej Los 29-Jun-18 1:53am    
And? What's wrong with your code?
Eric Lynch 29-Jun-18 8:04am    
You are not providing enough information for anyone to answer your question. Let's take a look at some of the problems with your question:

"i have below xml in the ip address"

Is this the entire XML document? If yes, the XML is not valid. If no, how are we supposed to guess at the rest of it?

"i am access the ip in postman <colleges>"

If you're trying to access the XML element <colleges>, this is not included in the sample data you provide. No one can tell you how to access an element that they cannot see.

"i have to read below, i am not sure how to get data"

If you're question is how to read a random XML document (that we cannot see), then
Maciej Los provided a solution. If you're question is more specific, then please be more specific.

From a response to the solution...

"thank you @Maciej, but i have already tried this"

That's great news. What went wrong? Did you get an error? If so, what error?

Without knowing the error, the contents of the string "sret", the complete contents of the XML document, the actual source code you tried, or having ANY other detail, it is not possible to guess the cause...possible causes are almost limitless.

In my opinion, the most likely possibilities are: 1) you copied the code incorrectly, 2) the XML document is not valid, or 3) a different character encoding (other than UTF-8) was used.

If you still want help, try providing people more information so that they can actually help you.

1 solution

If the only issue you've got is how to "convert" string returned by WebClient.UploadValues() method into xml document, check this:

C#
sret = System.Text.Encoding.Default.GetString(bret); //string containing xml data
XDocument xdoc = XDocument.Load(XmlReader.Create(new StringReader(sret)));
//further xml processing


See: XDocument Class (System.Xml.Linq)[^]
 
Share this answer
 
Comments
Maciej Los 29-Jun-18 2:21am    
Oh, Man! Could you be more specific and provide more details? Note: i'm not able to read in your mind or direct from your screen.
Maciej Los 29-Jun-18 3:04am    
Don't SHOUT! I'm not able to access your url, because it's LAN (not WAN!). See: https://en.wikipedia.org/wiki/Private_network

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900