Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Query XML file and display within HTML

Thread Tools

Query XML file and display within HTML

Bart Van der Donck
Posts: n/a
Jomo ((E-Mail Removed)) wrote:

> That's great. Thanks.
> Now what if I want to display the results within a
> specific section of an existing HTML page?

Not a problem. You could make a fixed string inside your HTML file (eg
inside a comment tag). Then read the file and replace that string by
your XML output result, before showing in to screen.

Say this is your HTML template, stored as /path/to/your/file.html:

<hr>My header<hr>
<hr>My footer<hr>

Your CGI file could then look like this:

print "Content-Type: text/html\n\n";
use CGI::Carp qw(fatalsToBrowser);
use XML::Simple;
my $found=0;
$q=~tr/+/ /;
my $xmlfile = XMLin("data.xml", forcearray=>1);
for my $record (@{$xmlfile->{RECORD}})
if (uc $record->{"ARTIST"}->[0] eq uc $q)
if ($found!=1)
print "<html><body>
No website found
open (R, "/path/to/your/file.html") || die "$!";
flock(R, 1) || die "Cant get LOCK_SH on file: $!";
while (<R>)
print $_;
close R;

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display HTML that is the data within and XML file. Cal Who ASP .Net 12 12-22-2009 12:12 PM
dealing with nested xml within nested xml within...... Ultrus Python 3 07-09-2007 09:00 PM
Query XML file and display within HTML Bart Van der Donck XML 1 01-07-2005 03:51 AM
Query XML file and display within HTML XML 1 01-01-2005 11:44 AM
CHtmlView: How to read html text before display, change and give to display changed html code? Marek Kurowski C Programming 1 08-18-2004 06:41 PM