Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display xml content in html

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
hi!

I'm new and unfamiliar to xml.
can someone please show me how I can take XML text and present it in html?

thanks..
 
Actually, PHP3 is probably more of what you want than XML. You'd create your php3 file, which contains commands to retrieve the data from an xml file and format and display it. Then you'd pass the filename of your xml file as a parameter: myphpfile.php3?filename=myxmlfile.xml

This lets you design your output once, and display many similar xml files.

Try these sites:

Rose/Miros
 
XSLT style sheets(another kind of xml document that is a conversion tool) when used with an xml document, will specify how the xml tags should be interpreted into html. Using XSLT mixed with some CSS style sheets, you can present your xml document data, just as if it were written in html. XSLT IS an official recommendation by the World Wide Web Consortium.
 
XSLT is really quite wonderful... I've just started using it myself. There's a good tutorial at plus a good reference and more advanced tutorial at .. in order to use XML/XSLT effectively you need to translate the XML to HTML on the server side (Netscape 6 and IE5.5/6 can do this, but you can't rely on people having these..) A good server-side utility to do this is SAXON ( ) which can run as a servlet. There are others listed on w3c's XSL page ( )
 
Use the <xsl:value-of select=&quot;@Fieldname&quot;/> tag.
 
Make this HTML document:
This code calls up an your xml file (whatever its called)
and an XSL stylesheet the .xsl sheet gives instructions on
how to display bits of XML data that you are interested in:

<html>
<head><title> YOUR TITLE </title>

<link rel=&quot;STYLESHEET&quot; type=&quot;text/css&quot; href=&quot;YOUR STYLESHEET.css&quot; />

<xml id=&quot;GIVE IT AN ID&quot; src=&quot;YOUR XML FILE.xml&quot;></xml>


</head>


<script language=&quot;javascript&quot;>
// Load XML
var xml = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;)
xml.async = false
xml.load(&quot;YOUR XML FILE.xml&quot;)

// Load the XSL
var xsl = new ActiveXObject(&quot;Microsoft.XMLDOM&quot;)
xsl.async = false
xsl.load(&quot;THE XSL FILE TO DISPLAY THE XML.xsl&quot;)


// Transform
document.write(xml.transformNode(xsl))


</script>
</body>
</html>


Here's a guide XSL sheet if you need it:
this is some code that makes a table and displays the
various elements I've pointed it to:


&quot;THE XSL FILE TO DISPLAY THE XML.xsl&quot;

<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl=&quot;<xsl:template match= &quot;/&quot;>
<html>
<body>

<table border=&quot;1&quot;>
<tr bgcolor=&quot;#33CCFF&quot;>
<td>
Author/Source
</td>
</tr>

<xsl:for-each select=&quot;PATH IN XML FILE OF THE NODE INFORMATION YOU WANT TO DISPLAY&quot; order-by=&quot;+AUTHOR&quot;>
<tr>
<td bgcolor=&quot;silver&quot;>
<xsl:value-of select=&quot;NAME OF NODE TO BE DISPLAYED&quot; />
</td>
</tr>


</xsl:for-each>
</table>


</body>
</html>
</xsl:template>
</xsl:stylesheet>


hope this of help just run the first html file in a browser and as long as it points to your xml and xsl files then the xsl should style it to look how you want.


Regards

Dan
 
Dan... This is great. I have been looking for an example like this for a few days. Perfect and simple... only it does not work in Mozilla browsers.

I know Mozilla uses &quot;document.implementation.createDocument&quot; to create an object, but my JS experience is limited and I am unsure how to modify your example.

Can you (or anyone) point me in the right direction?

Thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top