Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Query XML file and display within HTML

 
 
Bart Van der Donck
Guest
Posts: n/a
 
      01-15-2005
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:

<html>
<body>
<hr>My header<hr>
<!--g58s5s26d58esskolKjdX-->
<hr>My footer<hr>
</body>
</html>

Your CGI file could then look like this:

#!/usr/bin/perl
print "Content-Type: text/html\n\n";
use CGI::Carp qw(fatalsToBrowser);
use XML::Simple;
my $found=0;
my $q=$ENV{"QUERY_STRING"};
$q=~s/^artist=//;
$q=~tr/+/ /;
$q=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
my $xmlfile = XMLin("data.xml", forcearray=>1);
for my $record (@{$xmlfile->{RECORD}})
{
if (uc $record->{"ARTIST"}->[0] eq uc $q)
{
$result.=$record->{"URL"}->[0];
$found=1;
}
}
if ($found!=1)
{
print "<html><body>
No website found
</body></html>";
}
else
{
open (R, "/path/to/your/file.html") || die "$!";
flock(R, 1) || die "Cant get LOCK_SH on file: $!";
while (<R>)
{
$_=~s/<!--g58s5s26d58esskolKjdX-->/$result/i;
print $_;
}
close R;
}

--
Bart
 
Reply With Quote
 
 
 
Reply

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 jomo@dynamicdeveloper.co.uk 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



Advertisments