How to use this simple XML example to display?

G

Grace Tsai

Hi,

I am a beginner of XML.

I got a simple example as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget the meeting!</body>
</note>

How do I display this on the web?

1. In the webserver, anything should be done to let user (web browser)
to display xml?

2. Where the code of the example should put? In a web server's
directory? Any other software should be written to allow this XML
to display?

3. I am using Mozilla, anything I should enable?

Thanks.

Grace
 
L

Larry

Grace Tsai <[email protected]> said:
I got a simple example as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget the meeting!</body>
</note>

You might want to use XSL as to parse and format the XML file, the
following might be a good XSL file for your XML document:

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

<xsl:template match="/">

<html>
<head><title>My XML file</title></head>
<body bgcolor="#CCC">

<h2>My XML file</h2>

<b>To</b>: <xsl:value-of select="note/to"/><br />
<b>From</b>: <xsl:value-of select="note/from"/><br />
<b>Heading</b>: <xsl:value-of select="note/heading"/><br />
<b>Body</b>: <xsl:value-of select="note/body"/><br />

</body>
</html>

</xsl:template>

</xsl:stylesheet>

....then you would have to add this line to your XML document:

<?xml-stylesheet type="text/xsl" href="style.xsl"?>

Now your XML file would look like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget the meeting!</body>
</note>

Try and run it by internet explorer...bye
 
J

Jukka K. Korpela

Larry said:
You might want to use XSL as to parse and format the XML file

Maybe. And it might or might not have the desired effect.

XML documents don't make good web pages as such or even with a style
sheet, because browsers may not have support to the style sheet used,
or may have style sheet support disabled. Moreover, some browsers just
don't grok XML. What, for example, should a speech-based user agent do
when it gets an XML document?

Converting the XML document to an (X)HTML document server-side is the
best approach to making the content accessible on the web. This could
take place on the fly (client asks for a document, server picks up an
XML document, converts it, and sends the HTML result to the client)
or offline (the HTML output is generated whenever the XML document is
changed).

But _if_ you wish to throw XML at web browsers, then you can, in simple
cases, use a CSS style sheet, which is simpler than using XSL. In the
given case, you would probably want to make <to>Tove</to> to appear as
To: Tove
on a line of its own, perhaps with "To:" in bold. This would require
the use of generated content in CSS, so this isn't one of the simple
cases. (IE and Firefox do not support generated content.)
 
P

Peter Flynn

Grace said:
Hi,

I am a beginner of XML.

I got a simple example as follows:

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Dont forget the meeting!</body>
</note>

How do I display this on the web?

FAQ. http://www.ucc.ie/xml/#style
1. In the webserver, anything should be done to let user (web browser)
to display xml?
http://www.ucc.ie/xml/#mime

2. Where the code of the example should put? In a web server's
directory? Any other software should be written to allow this XML
to display?

If you want it converted to HTML on the server, use XSLT.
3. I am using Mozilla, anything I should enable?

No, it should work fine as-is.

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top