Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: XML learning experience a little painful  (Read 4166 times)

0 Members and 1 Guest are viewing this topic.

Dilbert

    Topic Starter
  • Moderator


  • Egghead

  • Welcome to ComputerHope!
  • Thanked: 44
    XML learning experience a little painful
    « on: March 23, 2006, 08:07:14 PM »
    OK, I was going to include this in my RPG thread, but I'm not planning on using XML in my game (though I could if I needed to). So it doesn't belong in that thread. Besides, blending the topics of PHP and XML would be a disaster - PHP's confusing enough as is. :)

    OK, I made a working XML and XLS. I know this because when I open the XML file in IE6, it displays as it should - an (X)HTML. However, when I view it on my server, I see the code - and the line pointing to the XLS is missing on the display.

    The code for the XML and XLS:

    Code: [Select]
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="test.xsl"?>
    <document>
    <facts>
    <funfact>The Grand Canyon is the deepest canyon on land.</funfact>
    <states>There are 50 states.</states>
    </facts>
    </document>

    Code: [Select]
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
    <body>
    <p>Fun facts</p>
    <xsl:for-each select="document/facts">
    <p><xsl:value-of select="funfact"/></p>
    <p><xsl:value-of select="states"/></p>
    </xsl:for-each>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>

    The output viewing as C:\Program Files\Apache Group\Apache2\htdocs\test.xml:

    Quote
    Fun facts

    The Grand Canyon is the deepest canyon on land.

    There are 50 states.

    Simple, but I got sick of Hello World! every time I learned something new. ;)

    Anyway, the output of
    http://127.0.0.1/test.xml
    :

     
    Quote
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    - <document>
      <funfact>The Grand Canyon is the deepest canyon on land.</funfact>
      <states>There are 50 states.</states>
      </document>

    Note the missing "<?xml-stylesheet type="text/xsl" href="test.xsl"?>" line in the online version, which renders fine in the file version. What causes this, and how may I get around it?
    « Last Edit: March 23, 2006, 08:08:08 PM by Timothy_Bennett »
    "The geek shall inherit the Earth."

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: XML learning experience a little painful
    « Reply #1 on: March 24, 2006, 12:06:48 AM »
    Looks to me like your Apache installation isn't set up with knowledge of XML as a MIME type.  Don't know where the config is on a Win install, so I may have to get back to you.
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos

    Dilbert

      Topic Starter
    • Moderator


    • Egghead

    • Welcome to ComputerHope!
    • Thanked: 44
      Re: XML learning experience a little painful
      « Reply #2 on: March 24, 2006, 12:16:51 AM »
      Whoa, I found it and fixed it!

      I went to the conf folder with the intent of editing the httpd.conf file. However,  I saw the file mime.types and edited it. I saw that pages that were html/htm had a double-tab, then the extension, like:

      Quote
      text/html                  html htm
      text/parityfec
      text/plain                  asc txt
      text/prs.lines.tag
      text/rfc822-headers
      text/richtext                  rtx
      [/pre]

      but the xml one was blank. I double-tabbed over, typed "xml" and hit save. Now, I get this:



      Not very complicated, but it IS exactly what I wanted. I think I got lucky on this one. :)

      [edit]And I now have a use for IE: It's the only browser that shows XML code without clicking "View Source". :)[/edit]
      « Last Edit: March 24, 2006, 12:18:45 AM by Timothy_Bennett »
      "The geek shall inherit the Earth."

      Rob Pomeroy



        Prodigy

      • Systems Architect
      • Thanked: 124
        • Me
      • Experience: Expert
      • OS: Other
      Re: XML learning experience a little painful
      « Reply #3 on: March 24, 2006, 02:26:17 AM »
      Yep, well done - that's the fix.  :)

      I haven't investigated XML much beyond the theory, for the very reason you outline: lack of support/adoption.  HTML+CSS+PHP+MySQL works just fine for me at the moment.
      Only able to visit the forums sporadically, sorry.

      Geek & Dummy - honest news, reviews and howtos

      Dilbert

        Topic Starter
      • Moderator


      • Egghead

      • Welcome to ComputerHope!
      • Thanked: 44
        Re: XML learning experience a little painful
        « Reply #4 on: March 24, 2006, 10:26:33 AM »
        IMHO, XML would be good for pieces of pages that require data storage, but it's not meant to be used to format an entire page. You could use it, for example, as a Web-based database. Of course, it shouldn't be used as the only content in a page.

        ***WARNING: IGNORE THE POST BELOW, IT'S THE RAMBLINGS OF A GUY WITH TOO MUCH TIME ON HIS HANDS***

        The W3C is nice enough to provide a few ways to format XML. It suggests:

        CSS - I didn't know this, but you can actually fomat XML with Cascading Style Sheets. Curious. The W3C insists, however, that it is NOT the future of formatting XML. Funny, that - it's a way to bypass the problems encountered by using the future of XML parsing.

        JavaScript - The W3C doesn't provide an example, just mentions in an esoteric passage in their XML tuts that it's possible.

        Finally, it's possible, they say, to use the <XML> tag in an HTML. That's odd, the strangest application I've seen for it yet. I don't know what kind of support browsers offer.

        There are apparently multiple methods of synchronizing HTML with XML. Sorry if you already know this, but you said you didn't investigate it, so I thought I'd let you know just in case. :)

        [edit]I tested the parsing ability of FireFox 1.5, Opera 8.52, Internet Explorer 6.0, Netscape 8.1 and Mozilla 1.7.12. Here are the results:

        FireFox - parsed my XML correctly.

        Opera - was a total mess.

        Internet Explorer - parsed correctly.

        Mozilla - parsed correctly.

        Netscape - parsed correctly.

        (X)HTML appeared fine on 4 out of 5 major browsers tested. Mind, these are the latest versions, so I don't know about older ones. But this is a pretty good score. And if you don't rely on (H)XTML for the whole page, it should work for all of them.[/edit]

        [edit]I removed the XSL stylesheet and its reference in the XML file for testing on showing code. Same browsers tested. Results:

        FireFox - upon realizing that there was no stylesheet, showed the document tree as expected. It gave a message at the top specifying that it couldn't find a XSL page and would show the tree.

        Opera - again, total mess.

        Internet Explorer - showed document tree.

        Mozilla - showed document tree. Same message as FireFox.

        Netscape - showed document tree. Same message as FireFox and Mozilla.

        XML has fairly good support nowadays - it's Opera that's falling behind the curve.[/edit]
        « Last Edit: March 24, 2006, 10:47:37 AM by Timothy_Bennett »
        "The geek shall inherit the Earth."