如何读取XML值
问题描述:
嗨我有以下网址需要从网址读取xml值
192.185.0.25:8080/red/info
我尝试过:
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);
答
如果您唯一的问题是得到的是如何将WebClient.UploadValues()
方法返回的字符串转换为xml文档,请检查:
If the only issue you've got is how to "convert" string returned byWebClient.UploadValues()
method into xml document, check this:
sret = System.Text.Encoding.Default.GetString(bret); //string containing xml data
XDocument xdoc = XDocument.Load(XmlReader.Create(new StringReader(sret)));
//further xml processing
请参阅: XDocument类(System.Xml.Linq) [ ^ ]