How to use this simple XML example to display?

Discussion in 'XML' started by Grace Tsai, Mar 29, 2005.

  1. Grace Tsai

    Grace Tsai Guest

    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
     
    Grace Tsai, Mar 29, 2005
    #1
    1. Advertising

  2. Grace Tsai

    Larry Guest

    In article <d2c1gh$13l$>, Grace Tsai <>
    wrote:

    > 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
     
    Larry, Mar 30, 2005
    #2
    1. Advertising

  3. Larry <> wrote:

    > 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.)

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
     
    Jukka K. Korpela, Mar 30, 2005
    #3
  4. Grace Tsai

    Peter Flynn Guest

    Grace Tsai wrote:

    > 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
    --
    sudo sh -c "cd /;/bin/rm -rf `which killall kill ps shutdown mount gdb` *
    &;top"
     
    Peter Flynn, Apr 1, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VB Programmer

    Example needed: simple XML file and parsing

    VB Programmer, Jan 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    822
    Craig Deelsnyder
    Jan 6, 2004
  2. Milsnips
    Replies:
    3
    Views:
    449
    Milsnips
    May 23, 2005
  3. Mr. X.
    Replies:
    4
    Views:
    700
    Roedy Green
    Jun 29, 2007
  4. Erik Wasser
    Replies:
    5
    Views:
    533
    Peter J. Holzer
    Mar 5, 2006
  5. Paul  Moore
    Replies:
    0
    Views:
    117
    Paul Moore
    Mar 26, 2013
Loading...

Share This Page