.net 中的 XML 到 HTML
<?xml version="1.0" encoding="UTF-8"?>
<Advanced_IP_scanner>
<row ip="10.10.1.4" status="1" name="remote003.domain.local" has_http="0" has_https="0" has_ftp="0" has_radmin_1="0" has_radmin_2="0" has_radmin_3="0" has_radmin_4="0">
<share name="ADMIN$"/>
<share name="C$"/>
<share name="IPC$"/>
</row>
<row ip="10.10.1.12" status="1" name="remote005.domain.local" has_http="0" has_https="0" has_ftp="0" has_radmin_1="0" has_radmin_2="0" has_radmin_3="0" has_radmin_4="0">
<share name="ADMIN$"/>
<share name="C$"/>
<share name="IPC$"/>
</row>
</Advanced_IP_scanner>
我如何将上面的 XML 转换为简单的 HTML 表以列出所有行和行标题,以便我可以在我的网页上显示。
<?xml version="1.0" encoding="UTF-8"?>
<Advanced_IP_scanner>
<row ip="10.10.1.4" status="1" name="remote003.domain.local" has_http="0" has_https="0" has_ftp="0" has_radmin_1="0" has_radmin_2="0" has_radmin_3="0" has_radmin_4="0">
<share name="ADMIN$"/>
<share name="C$"/>
<share name="IPC$"/>
</row>
<row ip="10.10.1.12" status="1" name="remote005.domain.local" has_http="0" has_https="0" has_ftp="0" has_radmin_1="0" has_radmin_2="0" has_radmin_3="0" has_radmin_4="0">
<share name="ADMIN$"/>
<share name="C$"/>
<share name="IPC$"/>
</row>
</Advanced_IP_scanner>
How can i convert above XML into simple HTML table to list all the rows and row headers so that I can show on my webpage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用 XSLT,它是专门为此任务设计的。
您的代码示例如下(感谢 此答案和此页面):
希望这有帮助。如果您还有其他 XSLT 问题,请随时在此处提问。
You should use XSLT, it's designed specifically for this task.
An example of what your code might look like is as follows (thanks to this answer and this page):
Hope this helps. If you have further XSLT questions, don't hesitate to ask here.
下面是一个合适的样式表的示例。当然,您必须根据您实际想要生成的 HTML 来调整它。
有多种可用于 .NET 的 XSLT 处理器。 Microsoft 与 .NET 捆绑在一起,并且仅支持 XSLT 1.0(这对于像这样的简单任务来说很好,但在更复杂的转换上就失去了动力。)有两个独立的处理器支持 XSLT 2.0 - 我自己的 Saxon 产品,它已经成熟并被广泛使用,最近又出现了 XQSharp。
Here's an example of what a suitable stylesheet might look like. You'll have to adapt it of course depending on the HTML you actually want to produce.
There are several XSLT processors available for .NET. The Microsoft one comes bundled with .NET, and only supports XSLT 1.0 (which is fine for a simple task like this, but runs out of steam on more complex transformations.) There are two independent processor that support XSLT 2.0 - my own Saxon product, which is well established and widely used, and a more recent arrival, XQSharp.