Using Perl with XML (part 1) (
Page 1 of 7 )
Converted your little black book into XML, and don't know what to do next? This article gets you started on the path to being an XML guru, demonstrating how to use Perl's SAX parser to parse and convert your XML into Web-friendly HTML.Unless you've spent the last couple of years under a rock, you know about XML,
the Extensible Markup Language, and its extended family of related technologies
- XSLT, XPath, XLink, WDDX et al. You may even have used it a couple of times,
creating XML documents to describe your address book or your CD collection, and
marveled at how simple the process is.
It's at this point that most
novice developers hit a brick wall. Sure, they know the theory of creating an
XML document, and they may even understand why the technology is so widely
discussed and praised. But when it comes to actually doing something with it -
converting that XML-encoded CD collection into something that can be read by a
browser, for example - there's simply not enough information out there to
provide guidance on how to take the next step.
Over the next few pages, I
will be attempting to rectify this a little bit, with an explanation of how you
can convert your XML data into browser-readable HTML. Since XML is nothing but
plain text, it makes sense to use a language which specializes in parsing text
documents...which is where Perl, that granddaddy of text processing languages,
comes in. There are a couple of basic approaches to parsing XML data; this
two-part article will explore the Perl implementation of each, together with
examples and illustrations.
I'll try and keep it simple - I'm going to
use very simple XML sources, so you don't have to worry about namespaces, DTDs
and PIs - although I will assume that you know the basic rules of XML markup,
and of Perl scripting. So let's get this show on the road.