Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert XML to something readable?

Tags:

xml

I have a huge xml file and i want to convert it to a readable format.

This is how my xml file looks like:

<entries>
<entry title="earth" id="9424127" date="2006-04-19T08:22:16.140">
<![CDATA[earth is the place where we live.]]>
</entry>
</entries>

So i have more than 5000 entries like this and i want to put them online so i can read them easily. How can i convert it?

This is the output that i want to have:

Earth

earth is the place where we live. (2006-04-19T08:22:16.140)

like image 621
sensahin Avatar asked Jul 05 '11 21:07

sensahin


People also ask

How to convert XML files to readable files?

To convert XML files to PDF files or readable files, you can use online tools available on the World Wide Web such as PDFelement, NovaPDF, and various others. There are instructions mentioned along with these offline tools and online tools on how to proceed with the conversion. Also, these tools are effective for low-scale conversions.

How to convert XML to text?

How to Convert XML to Text 1 Open an XMLIn this first step, double-click your XML file to open it via your default browser on the computer. 2 Print XMLHaving opened this XML file, you should next click the "Print" option in the browser used for loading... 3 Convert XML to Text See More....

How do I convert a compressed file to an XML file?

You cannot convert a compressed file to an XML file. However, if the compressed file is the compressed version of an XML file (or contains it), then you can get that file simply by uncompressing the compressed one, a process which might also be referred to as extracting the file you want from a set of files in a compressed archive.

How to open an XML file?

In this first step, double-click your XML file to open it via your default browser on the computer. Alternatively, you may right-click the file, so you load it using Notepad or Microsoft Word.


2 Answers

You could use an XSLT stylesheet to create a simple html table.

For example, this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes"/>
  <xsl:strip-space elements="*"/>

  <xsl:template match="node()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="/entries">
    <html>
      <body>
        <table border="1">
          <xsl:apply-templates/>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="entry">
    <tr>
      <td><xsl:value-of select="@title"/></td>
      <td>
        <xsl:apply-templates/>
      </td>
      <td>(<xsl:value-of select="@date"/>)</td>
    </tr>
  </xsl:template>

</xsl:stylesheet>

would create:

<html>
  <body>
    <table border="1">
      <tr>
        <td>earth</td>
        <td> earth is the place where we live. </td>
        <td>(2006-04-19T08:22:16.140)</td>
      </tr>
    </table>
  </body>
</html>
like image 85
Daniel Haley Avatar answered Nov 15 '22 10:11

Daniel Haley


I have used CSS for this kind of job a couple of times. This is a good guide: http://www.w3schools.com/xml/xml_display.asp

like image 29
Martin Avatar answered Nov 15 '22 10:11

Martin