【发布时间】:2012-10-31 00:03:33
【问题描述】:
好的,我会尽量快速简单地解释一下……
我要做的是从 xml 中提取四种不同的东西...首先是我正在使用的 XML 的here is the url,然后从那个 url XML 我试图只显示名称(符号),最后、高和低。
所以在我的应用程序中,当用户点击按钮获取股票报价时,现在出现的是来自该 XML 的所有内容,但我只想显示上面列出的这 4 件事。
这是我现在的代码...
HttpWebRequest myHttpWebRequest = null; //Declare an HTTP-specific implementation of the WebRequest class.
HttpWebResponse myHttpWebResponse = null; //Declare an HTTP-specific implementation of the WebResponse class
XmlTextReader myXMLReader = null; //Declare XMLReader
XPathNavigator nav;
XPathDocument docNav;
//Create Request
String stockQuote = "http://www.webservicex.net/stockquote.asmx/GetQuote?Symbol=T" + txtInfo.Text;
myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(stockQuote);
myHttpWebRequest.Method = "GET";
myHttpWebRequest.ContentType = "text/xml; encoding='utf-8'";
//Get Response
myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
//Load response stream into XMLReader
myXMLReader = new XmlTextReader(myHttpWebResponse.GetResponseStream());
docNav = new XPathDocument(myXMLReader);
// Create a navigator to query with XPath.
nav = docNav.CreateNavigator();
txtResults.Text = txtResults.Text + nav.Name + " - " + nav.Value + Environment.NewLine;
【问题讨论】:
标签: asp.net xml web-services xpath xpathdocument