Tutorial for XML for Perl
The Perl scripting language can be used to perform two important tasks: reading and writing XML files. Extensible Markup Language, or XML, is a customized program file that is used store data. It always stores its data in the same structure, so that its easy for software engineers to predict what can be used inside the XML file. This tutorial will show you how to create an XML parser in Perl, a tool that can be used to break-down XML files and read what's inside of them.
Instructions
-
-
1
Open up your code editing application or a plaintext editor.
-
2
Obtain an XML structure from an XML feed and paste it into a new text document, so that you can reference it as you program the parser. Examine the following example structure:
<SPORTSNEWS><INFO site"http://www.examplesportswebsite.com" sitename="Racing News">
Created by Sports News</INFO>
<article headline="Headline1"></article>
<article text="This is the article"></article>
</SPORTSNEWS>
-
-
3
Create a new text document to program the Perl parser. Use the following lines of code to define it as a Perl document and its function:
#!/usr/bin/perl -w
use strict;
use XML::Parser
use LWP::Simple
my $message
-
4
Build the portion of the parser that grabs the URL of the XML file and parses it by using the following lines of Perl code:
my $sportsnews = get(http://http://www.examplesportswebsite.com");
my $parser = new XML::Parser
-
5
Save your Perl script and open the file in a web browser to execute the code and view the data sent by the XML feed source.
-
1