获取信息表XML(Web服务的输出) [英] Get Information Form XML (output of web services)

查看:121
本文介绍了获取信息表XML(Web服务的输出)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
请帮助我
我的应用程序是C#Windows应用程序&
当我使用yahoo Web服务时,它返回xml结果,如何从中获取信息以及如何将结果作为要在Web浏览器中加载的网页返回到

Hello Every Body
Please Help Me
My Application is C# windows Application &
When i use yahoo web service it return xml result , how can i get information from it and how to return result as aweb page to be loaded in web browser

推荐答案

u可以使用XmlDocument获取Web服务结果,然后从中获取值.包括以下名称空间:
u can use XmlDocument to obtain the web service result and then get values from it. Include following namespaces:
using System.Net;
using System.IO;
using System.Xml;


尝试以下类型的代码:


Try this type of code:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://localhost/WebServiceDemo/DemoWebService.asmx/Add?x=50&y=12");
HttpWebResponse res = (HttpWebResponse)req.GetResponse();

XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(new StreamReader(res.GetResponseStream()).ReadToEnd());

lblResponse.Text = xdoc.OuterXml;

if (File.Exists("D:\\Demo.xml"))
	File.Delete("D:\\Demo.xml");
xdoc.Save("D:\\Demo.xml");


您可以使用xml类方法使用xdoc.SelectNodes或xdoc.SelectSingleNode方法从选定节点获取数据,并在其中提供XPath.

假设Web服务结果在根元素"Root"内的节点"Value"中包含值,则:


You can use xml class methods to get data from selected node using xdoc.SelectNodes or xdoc.SelectSingleNode methods and providing XPath in it.

Suppose web service result contains value in node "Value" inside root element "Root", then:

lblResult.Value = xdoc.SelectSingleNode("Root/Value").InnerText;


这篇关于获取信息表XML(Web服务的输出)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆