XML and Perl: Embedding XML in HTML | 2 | WebReference

XML and Perl: Embedding XML in HTML | 2

XML and Perl::Querying the file

xml-fetch.pl View source | Try it
This script retrieves a file from the Web, queries it for a specified list of comma delimited tags, and displays the tag name, attributes, and content.

Now it's time to get our feet wet. We're going to develop a script that will:

  1. Retrieve an HTML/XML document from a specified URL
  2. Query the file for a specified list of tags
  3. Print the tag names, attribute values, and content in an HTML table
  4. Optionally print the document below the element table

 

CGI parameters:
The following are a list of parameters that we will be passing to our CGI script via an HTML form.

  1. url - the full URL of the XML document, i.e. http://www.webreference.com/xml/dmv.xm
  2. fields - a comma delimited list of elements to search for, i.e. document,abstract,toc
  3. display - the script will optionally display the XML document after the element table is displayed if the value equals ON

 

Note: You can either submit the data to the CGI script via a form like this one, or you can embed the query in a URL like this. Below, I will be referring to line numbers in this numbered source file. You may want to print it out now for reference. When you are ready to install the script on your system, you can retrieve the full source.

 

The Code:

xml-fetch.pl View source | Try it
This script retrieves a file from the Web, queries it for a specified list of comma delimited tags, and displays the tag name, attributes, and content.

http://www.internet.com

Produced by Jonathan Eisenzopf and
Created: Feb. 14, 1999
Revised: Sep. 19, 2003

URL: http://www.webreference.com/perl/tutorial1/