.net net中XML到HTML的转换

.net net中XML到HTML的转换,.net,xml,xml-parsing,.net,Xml,Xml Parsing,如何将上述XML转换为简单的HTML表格,列出所有行和行标题,以便在网页上显示。您应该使用,它是专门为此任务设计的。 下面是代码的示例(感谢和): 希望这有帮助。如果您还有更多的XSLT问题,请在这里毫不犹豫地提问。下面是一个合适样式表的示例。当然,您必须根据实际想要生成的HTML对其进行调整 XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ; XslCompiledTransform myXslTrans = new XslCom

如何将上述XML转换为简单的HTML表格,列出所有行和行标题,以便在网页上显示。

您应该使用,它是专门为此任务设计的。
下面是代码的示例(感谢和):


希望这有帮助。如果您还有更多的XSLT问题,请在这里毫不犹豫地提问。

下面是一个合适样式表的示例。当然,您必须根据实际想要生成的HTML对其进行调整

XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ;
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(myStyleSheet);
XmlTextWriter myWriter = new XmlTextWriter("result.html",null);
myXslTrans.Transform(myXPathDoc,null,myWriter);

Ip扫描表
...
...
...
....

有几个XSLT处理器可用于.NET。Microsoft one与.NET捆绑在一起,只支持XSLT 1.0(对于像这样的简单任务来说很好,但在更复杂的转换中会失去动力)。有两个独立的处理器支持XSLT 2.0—我自己的Saxon产品,这是一个成熟且广泛使用的产品,还有一个是最近推出的,XQSharp.

你考虑过使用吗?@Donut,你应该把它作为一个答案。因为这正是他们需要看到的。
XPathDocument myXPathDoc = new XPathDocument(myXmlFile) ;
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(myStyleSheet);
XmlTextWriter myWriter = new XmlTextWriter("result.html",null);
myXslTrans.Transform(myXPathDoc,null,myWriter);
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="Advanced_IP_Scanner">
    <html>
      <head>
        <title>Ip Scanner Table</title>
      </head>
      <body>
        <table>
          <thead>
            <tr>
              <th>...</th>
              <th>...</th>
              ...
            </tr>
          </thead>
          <tbody>
             <xsl:apply-templates/>
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>
  <xsl:template match="row">
    <tr>
      <td><xsl:value-of select="@ip"/></td>
      <td><xsl:value-of select="@name"/></td>
      <td><xsl:value-of select="@status"/></td>
      <td><xsl:value-of select="@has-http"/></td>
      ....
    </tr>
  </xsl:template>
</xsl:stylesheet>