Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
HTML object
mk2004
Hi,
I was wondering if there is a way to create an HTML object from a string in PERL? I am parsing a DCR using Teamsite XML parser and would like to identify any html tags(like anchor, image tags...) in this field by using HTML parser. So before that i want to convert the string to an html object.
Thanks!
Find more posts tagged with
Comments
gzevin
most likely it's possible, but you should probably be more specific on which module you are going to use.
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
Johnny
HTML::TreeBuilder will do the trick for you.
It's part of the 6.1 distribution.
Though, if you are using strict xhtml you can find what you are looking for with your favorite xml parser.
John Cuiuli
gzevin
John
it's not that I don't know it - from mk2004's post I understand he already has something in mind.... but did not explain in details
cheers
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
Johnny
Hi Greg, hope all is well!
I was just giving a reply to his post, not yours.
Seemed like he was leading onto the use of a HTML parser..
John Cuiuli
dynamic_chart_title.zip
gzevin
Hi John,
you simply replied to my posting, so I thought you were talking to me
. no worries!
Greg Zevin, Ph.D. Comp. Sc.
Independent Interwoven Consultant/Architect
Sydney, AU
chart_interactivity.zip
mk2004
Thanks for the replies. I am using HTML:
arser. Let me know if there is a better way to do it...
Thanks!
Johnny
That's the problem, HTML:
arser is a low level module, if you read the documentation,it needs to be constructed by a bunch of HTML::Elements and you need something on top of that to build it all....
Hence something like HTML::TreeBuilder will take in a string or file and create it all for you.
John Cuiuli
Adam Stoller
Is TreeBuilder available for Perl 5.005_03? (I know it comes with TS6's Perl 5.8.2)
If it is, of if one is using TS6 - the following code does, I think, what you're looking for (up to a point):
#!
/path/to/iwhome
/iw-perl/bin/iwperl
use strict;
use warnings;
# if using pre-TS6, put '-w' on #! line and leave out this pragma
use TeamSite::XMLnode;
use HTML::TreeBuilder;
my $xml = '';
{
local $/;
$xml = <DATA>;
}
my $root = TeamSite::XMLnode->new($xml);
die "parsing error" if (!defined($root));
my $v = $root->value('bar');
print "$v\n";
my $tree = HTML::TreeBuilder->new_from_content($v);
my
@nodes
= $tree->guts;
for (@{$tree->extract_links()}){
my($link, $elem, $attr, $tag) =
@$_
;
print "$tag element: $attr = '$link'\n";
}
__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE record SYSTEM "dcr4.5.dtd">
<record name="foo" type="content">
<item name="bar">
<value>
This is an image <img src="some_image.jpg"/> - yes?
This is a link <a href="
http://devnet.interwoven.com">here</a>
</value>
</item>
</record>
I run this and I see:
This is an image <img src="some_image.jpg"/> - yes?
This is a link <a href="
http://devnet.interwoven.com">here<
/a>
img element: src='some_image.jpg'
a element: href = '
http://devnet.interwoven.com'
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
Johnny
Yes, I was using the CPAN distribution prior to TS 6.
Though I couldn't tell you what module version it was.
John Cuiuli