1

Here is my xml:

<Catalog>
    <catalogDetail catalogId="DemoCatalog">
        <catalogName>Demo Catalog</catalogName>
    </catalogDetail>
    <catalogDetail catalogId="GoogleCatalog">
        <catalogName>Google Catalog</catalogName>
    </catalogDetail>
</Catalog>

I want it to be read in HTML file how can I do this???

4
  • Is that a XML string, or a XML document (resource)? Commented Apr 10, 2012 at 12:21
  • 2
    In pure html, it's impossible. You'll have to use javascript or create the html page at server-sided. Commented Apr 10, 2012 at 12:21
  • HTML is a static programming language. You will need another language like php or javascript to do anything like this. Commented Apr 10, 2012 at 12:21
  • 2
    @dragon112 — HTML is not a programming language. Commented Apr 10, 2012 at 12:23

3 Answers 3

2

To do this your HTML file should contain some JavaScript code, so you will want to learn how to parse XML in Javascript.

Here is a good StackOverflow question on this topic: XML parsing in JavaScript

Sign up to request clarification or add additional context in comments.

Comments

1

You can do by using PHP's XML Library called simplexml for more information check this link http://www.w3schools.com/php/php_xml_simplexml.asp

Comments

1

NOTE : If you can elaborate on what technology you're using, I'll try to provide a more complete example.

I would suggest using XSLT for this. With XSLT, you can pass in the XML fragment, parse it, and return formatted HTML.

Here's an example XSLT document that converts XML to HTML:

<?xml version="1.0" encoding="utf-8"?>  
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">  
    <xsl:output method="html" indent="yes"/>       
    <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>  
                <td>  
                  <xsl:value-of select="artist"/>  
                </td>  
              </tr>  
            </xsl:for-each>  
          </table>  
        </body>  
      </html> 
    </xsl:template>   
</xsl:stylesheet>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.