0

I am looking for a online program that parses any xml to html. For instance, if I have the following xml layout

<users>
    <user>
         </name>john</name>
         <pictures>
              <pic1>URL of picture1.png</pic1>
              <pic2>URL of picture2.png</pic2>
         </pictures>
    </user>
    <user>
         </name>mary</name>
         <pictures>
              <pic1>URL of picture1.png</pic1>
              <pic2>URL of picture2.png</pic2>
         </pictures>
    </user>
</users>

it can create an html page displaying the content of the nodes and give some minimal formatting for easy reading. Any such tool?

Edit: I just gave an example, I want a generic tool that can parse any xml without knowing its structure beforehand.

4

2 回答 2

0

解决此问题的一种方法是应用 XSLT 转换。

您需要创建一个 XSL 样式表,例如...

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
    <title>Contacts</title>
</head>
<body>
    <xsl:for-each select="//user">
        <h2><xsl:value-of select="name" /></h2>
        <p><xsl:value-of select="pictures/pic1" /></p>
        <p><xsl:value-of select="pictures/pic2" /></p>
    </xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet> 

然后在您的 xml 文件顶部链接到它。在下面的示例中,第二行链接到名为“myStyleSheet.xsl”的样式表。

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="myStyleSheet.xsl"?>
<users>
    <user>
         <name>john</name>
         <pictures>
              <pic1>URL of picture1.png</pic1>
              <pic2>URL of picture2.png</pic2>
         </pictures>
    </user>
    <user>
         <name>mary</name>
         <pictures>
              <pic1>URL of picture1.png</pic1>
              <pic2>URL of picture2.png</pic2>
         </pictures>
    </user>
</users>
于 2013-10-23T06:25:28.687 回答
-1

你可以试试这个。

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog_choose

<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
  <th>Title</th>
  <th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
  <td><xsl:value-of select="title"/></td>
  <xsl:choose>
  <xsl:when test="price > 10">
     <td bgcolor="#ff00ff">
     <xsl:value-of select="artist"/>
     </td>
  </xsl:when>
  <xsl:otherwise>
     <td><xsl:value-of select="artist"/></td>
  </xsl:otherwise>
  </xsl:choose>
  </tr>
</xsl:for-each>
 </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
于 2013-10-23T05:52:17.593 回答