<table border="1">
<th>Title</th>
<th>price</th>
<tr>
<td>book</td>
<td>$20</td>
</tr >
<tr>
<td>book2</td>
<td>$19</td>
</tr>
</table>

Dani AI

Generated

Thread goal recap: wanted a plain XML representation of the HTML table (no scripting). correctly pointed out that XML has no predefined tags — you design tags that describe your data. correctly reminded that a well-formed XML document needs a single root element and, when showing XML inside an HTML page, angle brackets must be escaped.

A few concise rules to follow for an educational XML example:

  • One root element that contains all rows.
  • One element per row (e.g., a "product" or "item"), with child elements for fields (title/name, price).
  • Avoid spaces or leading numbers in tag names; use elements for primary data and attributes only for small metadata.
  • Escape special characters (&, <, >) in XML content or wrap problematic content in CDATA sections.
  • If you intend to display the XML on a web page as code, escape angle brackets (as noted) or serve it as plain text / wrap in <pre><code>.

If the goal is to show how that XML could render as an HTML table without client-side scripting, an XSLT stylesheet is the simplest pure-XML approach. Save your data as one XML file and a separate XSLT file; browsers or command-line tools (xsltproc) can apply the transform.

Example XML input (data file):

<catalog>
  <product>
    <name>Learning XML</name>
    <price>20.00</price>
  </product>
  <product>
    <name>HTML Basics</name>
    <price>19.00</price>
  </product>
</catalog>

Example XSLT (transform to an HTML table):

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/catalog">
    <html><body>
      <table border="1">
        <tr><th>Title</th><th>Price</th></tr>
        <xsl:for-each select="product">
          <tr>
            <td><xsl:value-of select="name"/></td>
            <td><xsl:value-of select="price"/></td>
          </tr>
        </xsl:for-each>
      </table>
    </body></html>
  </xsl:template>
</xsl:stylesheet>

Validation and reading: the W3C XML Recommendation and MDN’s XML overview are authoritative references for well-formedness, namespaces, and XSLT usage: W3C XML Recommendation and MDN — Introduction to XML.

Recommended Answers

All 12 Replies

Please use code tags and don't put the (entire) question in the title.

Do you mean to ask how to read XML and put it in a table? If so, do you want to use PHP or Javascript for that?

no no.i want a XML code to this HTML table for education purpose only.I don't want this to do anything .So no need of scripting langs.Just the XML
Thanks

Ah. You have to use &lt; and &gt; instead of < and >.

can you write the XML to above one please?

Well, as that's downvoted, it's probably not what you want? But to answer your question, no, I'm not going to write XML for you. It's really simple and there's a lot to find about it, for example the link I posted above.

I'm not sure but do you want this table as XML structure ? XML is not like HTML, XML has not fixed predefine tags whether HTML has. You must define your own tag that related with the type of the data as much as you need.
Is that what you want, link would be appreciate for you, because you'll need to learn.

yeah,i want that in XML structure .and don't want it to do anything too.I am confused because there are a lots of ways.Looking for the best way
here you go,+1 then lol

OK. I'm not XML expert. But I can do a little bit like following.

<?xml version="1.0"?>
<book>
    <title>XML</title>
    <price>$3.0</price>
</book>
<book>
    <title>HTML</title>
    <price>$4.0</price>
</book>

As understanding your table, you've only two title, and price for each book. You can add addition element such <isbn>23232</isbn><published_date>Jun-28-2012</published_date> , ISBN number and the published date of the book as you like.
Hope that it will appreciate for you.

Yes, indeed. An XML should also, however, include a single root element, such as this:

<?xml version="1.0"?>
<library>
    <book>
        <title>XML</title>
        <price>$3.0</price>
    </book>
    <book>
        <title>HTML</title>
        <price>$4.0</price>
    </book>
</library>

, thanks man. You're right, I forgot it.

great.thanks for answeres both of you :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.