使用C#从XML到网页 [英] XML to Web Page Using C#

查看:95
本文介绍了使用C#从XML到网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 请帮帮我
如果您有xml内容(或文件,例如yahoo天气服务结果)
,如何在c#Windows应用程序的Web浏览器中将其加载为网页而不是xml内容
谢谢.

解决方案

您是否仔细检查了Yahoo Weather RSS提要响应查询的XML结果?

例如:[^ ]

您将看到XML包含指向Yahoo格式的HTML表示的链接.查看< link>根节点"Channel:"下的Item子节点下的节点.

 <  项目 > 
  <  标题 > 桑尼维尔的条件,美国太平洋标准时间上午9:38太平洋标准时间<  /title   > 
  <   geo:lat  >  37.37 <  /geo:lat  > 
  <   geo:long  > - 122.04 <  /geo:long  > 
  <  链接 >  http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html<  /link  >  

因此解析XML(通过DOM或纯旧文件)搜索(或字符串搜索),提取HTML链接,对该链接进行获取",然后重新使用返回的HTML.

现在,如果您的目的是提取Yahoo Weather RSS XML响应中的数据,并以您自己的HTML格式显示它:这是另一个问题.为此,您可以构建自己的XSLT转换,也可以自己解析文件,提取所需内容并生成自定义HTML.

无论哪种情况,您都应遵循Yahoo的归因指南,该准则在此答案的服务条款"中提供的第一个链接中找到.


网页正在使用HTML.您可以使用XSLT在HTML中转换XML,然后加载HTML.


hi Please help me
if you have an xml contents(or file ie yahoo weather service result)
,how to load it as a web page not xml contents in web browser in c# windows application
thanks.

解决方案

Have you examined closely the XML result of a Yahoo Weather RSS feed in response to a query ?

For example: [^]

You will see that the XML includes a link to an HTML representation in the Yahoo format. Look at the <link> node under the Item sub-node under the root-node "Channel:"

<item>
  <title>Conditions for Sunnyvale, CA at 9:38 am PST</title>
  <geo:lat>37.37</geo:lat>
  <geo:long>-122.04</geo:long>
  <link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>

So parse the XML (either via the DOM, or just plain old file-searching, or string searching), extract the HTML link, do a "get" on that link, and then re-use the HTML returned.

Now, if your purpose is to extract the data in a Yahoo Weather RSS XML response, and present it in your own HTML format: that''s another problem. For that, you can either construct your own XSLT transform, or parse the file yourself, extracting what you need, and generating custom HTML.

In either case you should follow the Yahoo guidelines for attribution, found in the first link given in this answer under "Terms of Service."


Web pages are using HTML. You can use XSLT to transform XML in HTML then load the HTML.


这篇关于使用C#从XML到网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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