I want to link my xml file to my html page

I created an XML file that I would like to display on my HTML page, which I also created. Can someone tell me how to do this.

<?xml version="1.0"?>
<Family>
<Mom>Alison</Mom>
<age>44</age>
<son>Ian</son>
<age>8</age>
<son>Seth</son>
</Family>

I would like to read this on my html page

+3
source share
4 answers

a) Just link the Xml file

You can link to your Xml file from the Html page using Server Side Includes.

If your web server is configured to enable this feature (usually this is disabled for security reasons), all you have to do is rename your Html page to .shtml and add the server command include.

foo.shtml

<html>
    <head/>
    <body>
    <!--#include file="bar.xml" -->
    </body>
</html>

bar.xml

<?xml version="1.0"?>
<Family>
    <Mom>Alison</Mom>
    <age>44</age>
    <son>Ian</son>
    <age>8</age>
    <son>Seth</son>
</Family>

This will display the text Alison 44 Ian 8 Sethin your browser.


b) Rendering your Xml file as Html

Xml Html wenuxas, .


c) Xml HTML

Xml Ajax, , .

+4

XSLT - XML. , .

XML, , . , :

<?xml version="1.0"?>
<?xml-stylesheet href="bla.xsl" type="text/xsl" ?>
<family>
   <person>
      <role>Mom</role>
      <name>Alison</name>
      <age>44</age>
   </person>
   <person>
      <role>Father</role>
      <name>Ben</name>
      <age>45</age>
   </person>
   <person>
      <role>Son</role>
      <name>Ian</name>
      <age>8</age>
   </person>
</family>

XSLT :

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
  <h2>Family</h2>
    <table border="1">
      <tr bgcolor="#9acd32">
    <th>Role</th>
        <th>Name</th>
        <th>Age</th>
      </tr>
      <xsl:for-each select="family/person">
          <tr>
        <td><xsl:value-of select="role"/></td>
        <td><xsl:value-of select="name"/></td>
        <td><xsl:value-of select="age"/></td>
          </tr>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
+3

If you just want to display the XML contents as they look in the file, you can search and replace all the brackets (<becomes & lt; and> become & gt;), then insert the result between the <preliminary> and </pre> tags.

+1
source

I would say that the most common way is to use a server-side development platform, such as ASP.NET, to read an XML file and then format it into page layout.

If there is a more direct way to include XML content in an HTML page, I am not familiar with it.

0
source

Source: https://habr.com/ru/post/1785244/


All Articles