CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Insert HTML into existing page using CGI

 



TallMonke
Novice

Jul 30, 2009, 8:25 PM

Post #1 of 11 (1715 views)
Insert HTML into existing page using CGI Can't Post

I have a perl script to parse and filter an XML file through CGI. That part is working quite well (yay for my first real large perl script!). However, I would like to have the return HTML inserted into a tag at a particular ID/Name. Is there a more elegant solution other than opening the calling HTML, insert the filtered results at the appropriate location, and returning the entire page new?

Thanks in advance!


KevinR
Veteran


Jul 30, 2009, 9:21 PM

Post #2 of 11 (1712 views)
Re: [TallMonke] Insert HTML into existing page using CGI [In reply to] Can't Post

The answer will most likely depend on how you are parsing the XML file.
-------------------------------------------------


TallMonke
Novice

Jul 31, 2009, 5:15 AM

Post #3 of 11 (1707 views)
Re: [KevinR] Insert HTML into existing page using CGI [In reply to] Can't Post

Using XML::Simple, for now it is the only parser I have available outside of rolling my own. I do not have control over the perl modules loaded.


KevinR
Veteran


Jul 31, 2009, 11:00 AM

Post #4 of 11 (1703 views)
Re: [TallMonke] Insert HTML into existing page using CGI [In reply to] Can't Post

I don't have too much experience with XML::Simple but it does parse XML into a data structure that you should be able to use to change specific elements of the data. Writing it all back to a file might be the hardest part because XML::Simple (if I remember correctly) puts everything into a hash so if original order of the file is important that might be lost. Sorry I can't be of more help.
-------------------------------------------------


TallMonke
Novice

Aug 1, 2009, 7:44 AM

Post #5 of 11 (1699 views)
Re: [KevinR] Insert HTML into existing page using CGI [In reply to] Can't Post

I am filtering the XML for specific (user chosen) content and returning the XML results as HTML. I can return the results as a new web page easily, but was wondering if there was a way to "embed" or insert the HTML table into the calling HTML file at a specific ID tag?



In Reply To
I don't have too much experience with XML::Simple but it does parse XML into a data structure that you should be able to use to change specific elements of the data. Writing it all back to a file might be the hardest part because XML::Simple (if I remember correctly) puts everything into a hash so if original order of the file is important that might be lost. Sorry I can't be of more help.



KevinR
Veteran


Aug 1, 2009, 9:48 AM

Post #6 of 11 (1697 views)
Re: [TallMonke] Insert HTML into existing page using CGI [In reply to] Can't Post

Like I said, XML::Simple parses the data in a data structure, you can examine that data structure with the Data::Dumper module and then hopefully decide on an approach to modifying it.
-------------------------------------------------


TallMonke
Novice

Aug 3, 2009, 9:01 AM

Post #7 of 11 (1676 views)
Re: [KevinR] Insert HTML into existing page using CGI [In reply to] Can't Post

The problem isnt modifying the XML, that is working. The question is inserting HTML into an existing HTML page? Is it possible to dynamically insert an HTML snippet on the server side through CGI without creating an entirely new HTML page? (i.e. return "<table>...</table>" instead of "<html><head></head><body><table>...</table></body></html>") Thanks


KevinR
Veteran


Aug 3, 2009, 9:11 AM

Post #8 of 11 (1674 views)
Re: [TallMonke] Insert HTML into existing page using CGI [In reply to] Can't Post

If the CGI script has permission to write to the server then it is possible. The question then becomes how would the CGI script know where to insert the new data (or replace existing data) in the existing document. That is generally done with regular expressions, but it depends on the specific html document.
-------------------------------------------------


FishMonger
Veteran / Moderator

Aug 3, 2009, 9:16 AM

Post #9 of 11 (1673 views)
Re: [TallMonke] Insert HTML into existing page using CGI [In reply to] Can't Post

Sounds like what you really want/need is to use one of the html templates.

Here are 2 of the options.

HTML::Template - Perl module to use HTML Templates from CGI scripts
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm

Template::Toolkit - Template Processing System
http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template/Toolkit.pod


(This post was edited by FishMonger on Aug 3, 2009, 9:16 AM)


KevinR
Veteran


Aug 3, 2009, 9:20 AM

Post #10 of 11 (1670 views)
Re: [FishMonger] Insert HTML into existing page using CGI [In reply to] Can't Post


In Reply To
Sounds like what you really want/need is to use one of the html templates.

Here are 2 of the options.

HTML::Template - Perl module to use HTML Templates from CGI scripts
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm

Template::Toolkit - Template Processing System
http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template/Toolkit.pod


I agree, a template system sounds like the ticket here.
-------------------------------------------------


TallMonke
Novice

Aug 3, 2009, 11:23 AM

Post #11 of 11 (1664 views)
Re: [KevinR] Insert HTML into existing page using CGI [In reply to] Can't Post

Thats what I was looking for. I will try it out and see if it works! Thanks!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives