Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
XML

Posted by Garrie (Garrie), 7 October 2002
Can anyone recommend a good place to start learning about XML?
I've looked at a number of websites and I am still confused about how to use XML. In particular, how to use XML to generate dynamic webpages.

- Garrie

Posted by John_Moylan (jfp), 7 October 2002
A good primer(s) for XML can be found at:
http://www.topxml.com/xml/learnxml.asp

XML is a way of saving your content/data in a structured form within a text doc or database.

You then parse the XML tags to extract the relevant data, what you do with it is up to you, but as you mentioned in your post generating web pages is a popular use for XML.

eg: extract your XML data and sent it to an html template to build and deploy your html page.
(This is a separation of content, logic and presentation, and is a good thing)
XML = Content
Programming lang = Logic
presentation = Template


The bit that does the parsing and building could be wriiten in any language, popular examples being "Perl, php, java".

You really need to decide on a language before specifics can be given on generating dynamic content, but php would be a nice easy route. (www.php.net)

jfp

Posted by Garrie (Garrie), 7 October 2002
Thanks I'll have a look.
It will probably be PHP I'll use to generate the pages.
So any help along those lines will be appreciated.

- Garrie


Posted by John_Moylan (jfp), 7 October 2002
Then I'll point you towards some urls and a good book.

I've not personally used the sites tutorials as I prefer my tutorials to come from tree's.
Url's:
http://www.zend.com/zend/tut/tutbarlach.php
http://www.analysisandsolutions.com/code/phpxml.htm

Books:
Beginning PHP4, published by WROX (make sure its PHP4, there is a older version of the book still being sold) is a good primer for php and includes a section on XML parsing.
No talk on templating here though, but I suggest you look at http://smarty.php.net/ for starters, there is another called fast template but smarty is faster and more extendable.

Have the appropriate amound of fun.

jfp

Posted by admin (Graham Ellis), 8 October 2002
For formatting data that's held in XML format, you probably want to have a look at XSLT (XML Stylesheet Language Transforms).

An XSLT document is a set of directives telling a formatter how to handle data found in an XML document, and it's written in XML itself, using a specific tag set that ensures that it's XSLT.

Perhaps an example would help?

Here's a file of XML:
Code:
<?xml version="1.0"?>
 <dromedaries>
   <species name="Camel">
     <humps>1 or 2</humps>
     <disposition>Cranky</disposition>
   </species>
   <species name="Llama">
     <humps>1 (sort of)</humps>
     <disposition>Aloof</disposition>
   </species>
   <species name="Alpaca">
     <humps>(see Llama)</humps>
     <disposition>Friendly</disposition>
   </species>
</dromedaries>


Here's the XSLT that I might use to translate it into HTML:
Code:
<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="/">
 <html>
 <head><title>Know Your Dromedaries</title></head>
 <body>
   <table bgcolor="#eeeeee" border="1">
   <tr>
   <th>Species</th>
   <th>No of Humps</th>
   <th>Disposition</th>
   </tr>
   <xsl:for-each select="dromedaries">
     <xsl:apply-templates select="./species" />
   </xsl:for-each>
 </table>
 </body>
 </html>
</xsl:template>

<xsl:template match="species">
 <tr>
 <td><xsl:value-of select="@name" /></td>
 <td><xsl:value-of select="humps" /></td>
 <td><xsl:value-of select="disposition" /></td>
 </tr>
</xsl:template>

</xsl:stylesheet>


And here's a Perl program to do the conversion:
Code:
use XML::LibXSLT;
use XML::LibXML;

my $parser = XML::LibXML->new();
my $doc = $parser->parse_file("camels.xml");
my $style_doc = $parser->parse_file("camels.xsl");

my $xslt = XML::LibXSLT->new();
my $stylesheet = $xslt->parse_stylesheet($style_doc);
my $results = $stylesheet->transform($doc);
my $output = $stylesheet->output_string($results);

print $output;




This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho