如何在C#中将XML转换为HTML [英] How to convert XML to Html in c#

查看:57
本文介绍了如何在C#中将XML转换为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这是将xml转换为html的最好方法,目前我正在使用Xpathnavigator和xpathnodeiterator来查询和遍历xml.这可以正常工作,但是我需要将此xml转换为html,并在浏览器中将其与某些表一起显示,这是实现此目的的最佳方法.而且xml并非总是恒定不变的,我的意思是xml是动态生成的. Xml在以下

Hello everyone,

Which is the best way to convert xml to html, currently i am using Xpathnavigator and xpathnodeiterator to query and traverse the xml. This works fine, but i need to convert this xml to html,and display it in browser with some tables, which is the best way to achieve this. And the xml is not constant always, i mean the xml is generated dynamically. Xml is below

- 
<win32_networkadapter>
<entity>
  <index>1</index> 
  <speed /> 
  <manufacturer /> 
  <pnpdeviceid /> 
  <name>RAS Async Adapter</name> 
  <adaptertype /> 
  </entity>
- <entity>
  <index>2</index> 
  <speed /> 
  <manufacturer>Microsoft</manufacturer> 
  <pnpdeviceid>ROOT\MS_L2TPMINIPORT\0000</pnpdeviceid> 
  <name>WAN Miniport (L2TP)</name> 
  <adaptertype /> 
  </entity>
</win32_networkadapter>



该xml包含系统中网络适配器的详细信息,以获取详细信息,其中使用了wmi并动态生成了xml.因此,一个系统可能包含上述xml中的2个网络适配器,而另一个系统可能包含3个或4个网络适配器,在这种情况下xml会增长.在这种情况下,如何从该xml动态生成html.在浏览器的表中显示网络详细信息.

谢谢您



This xml contains the details of the network adapters in a system, to get details wmi is used and xml is generated dynamically. So one system may contain 2 network adapter as in the above xml and other system may contain 3 or 4 network adapters in which case the xml grows. In this case how can generate html from this xml dynamically. Display the network details in tables in browser.

THank you

推荐答案

此链接将为您提供帮助
http://www.w3schools.com/xml/xml_to_html.asp [
This Link will Help you
http://www.w3schools.com/xml/xml_to_html.asp[^]


在您的 ASP.NET 网络表单中添加新XmlDataSource 并在rutime中将数据加载到其中.
然后添加GridView ListView 来显示数据源的内容,方法是将它们的DataSourceID 设置为添加的XmlDataSource ID的实例.

希望对您有所帮助.

编辑(在您的评论后):
因此,只需遍历节点并将它们的名称和属性作为HTML标记写入StringBuilder,然后对该字符串进行任何操作即可.

使用XML的帮助程序库:
http://htmlagilitypack.codeplex.com/ [ ^ ]
In your ASP.NET webform add new XmlDataSource and load your data into it at rutime.
Then add a GridView or ListView to show the content of datasource by setting DataSourceID of them to the instance of the added XmlDataSource ID.

Hope it helps.

Edit ( after your comment ):
So simply traverse into the nodes and write their names and attributes as HTML tags into a StringBuilder and then do whatever you want with that string.

Helper library to work with XMLs :
http://htmlagilitypack.codeplex.com/[^]


根据您在Solution-2中的评论.
Based on your comments in Solution-2.
报价:

我正在使用Windows窗体....我如何在Windows窗体中使用它,...谢谢

I am using windows forms .... How can i do it in windows form ,...Thank you


为此,请使用" XSLT "将XML转换为HTML.

http://blog. logiclabz.com/c/net-c-function-to-convert-xml-document-into-html-string-using-xslt.aspx

http://www.java2s.com/Code/CSharp/XML/XML/XMLtransformationtransformXMLfiletoHTMLfile.htm


For this use "XSLT" to transform your XML into HTML.

http://blog.logiclabz.com/c/net-c-function-to-convert-xml-document-into-html-string-using-xslt.aspx

http://www.java2s.com/Code/CSharp/XML/XMLtransformationtransformXMLfiletoHTMLfile.htm


这篇关于如何在C#中将XML转换为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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