How to display XML data as HTML (loading XML/XSL)

Source: Internet
Author: User

There are several ways to load XSL and XML:

1. Client loading (javascript)

<Html>

<Body>

 

<Script type = "text/javascript">

Var xmlDoc = null;

If (window. ActiveXObject)

{

// Code for IE

XmlDoc = new ActiveXObject ("Microsoft. XMLDOM ");

}

Else if (document. implementation. createDocument)

{

// Code for Mozilla, Firefox, Opera, etc.

XmlDoc = document. implementation. createDocument ("", "", null );

}

Else

{

Alert ('your browser cannot handle this script ');

}

If (xmlDoc! = Null)

{

XmlDoc. async = false;

XmlDoc. load ("cd_catalog.xml ");

 

Document. write ("<table border = '1'> ");

 

Var x = xmlDoc. getElementsByTagName ("CD ");

For (I = 0; I <x. length; I ++)

{

Document. write ("<tr> ");

Document. write ("<td> ");

Document. write (

X [I]. getElementsByTagName ("ARTIST") [0]. childNodes [0]. nodeValue );

Document. write ("</td> ");

 

Document. write ("<td> ");

Document. write (

X [I]. getElementsByTagName ("TITLE") [0]. childNodes [0]. nodeValue );

Document. write ("</td> ");

Document. write ("</tr> ");

}

Document. write ("</table> ");

}

</Script>

 

</Body>

</Html>

 

 

2. server load (Asp.net)

 

<% @ Control Language = "c #" %>
<% @ Import Namespace = "System. Xml" %>
<% @ Import Namespace = "System. Xml. Xsl" %>
<% @ Import Namespace = "System. Xml. XPath" %>
<Script runat = "server" language = "c #">
Public string xmlSource, writable source;
Void Page_Load (){
XmlDocument docXml = new XmlDocument ();
DocXml. Load (Server. MapPath (xmlSource ));
Inclutransform docXsl = new inclutransform ();
DocXsl. Load (Server. MapPath (program source ));
DocXsl. Transform (docXml, null, Response. Output );
// Chapter. Text = docXml. TransformNode (docXsl );
}
</Script>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.