GBrowse
view release on metacpan or search on metacpan
conf/MobyServices/text_xml_renderer.pm view on Meta::CPAN
package MobyServices::text_xml_renderer;
use strict;
use XML::LibXML;
use MOBY::MobyXMLConstants;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(render type);
sub types {
return ["text-xml"];
}
sub render {
my ($DOM, $htmldir,$imgdir) = @_;
my $content;
$content = &getStringContent($DOM);
$content =~ s/<!\[cdata\[/<[CDATA[/ig;
$content =~ s/<([^>]+)>/<$1>/g; # mask '>' and '<' in tags
return ("<pre>$content</pre>");# the 0 indicates that we have only rendered the top-level XML of this object
}
sub getStringContent {
my ($ROOT) = @_;
my $content;
my @childnodes = $ROOT->childNodes;
foreach (@childnodes){
next unless ($_->nodeType == ELEMENT_NODE);
next unless ($_->localname eq "String");
my $article = $_->getAttributeNode('articleName');
$article = $_->getAttributeNode('moby:articleName') unless $article;
next unless $article;
next unless $article->getValue eq 'content'; # the articleName for String content of a text-xml node
foreach my $subnode($_->childNodes){ # if it is correct, then get the text content
next unless (($subnode->nodeType == TEXT_NODE) || ($subnode->nodeType == CDATA_SECTION_NODE));
$content .=$subnode->textContent;
}
$ROOT->removeChild($_);
last;
}
return $content;
}
1;
=head1 NAME
text_xml_renderer.pm - a renderer (HTML) for text_xml type MOBY Objects
=head1 AUTHOR
Please report all bugs to Mark Wilkinson (markw at illuminae.com)
=head1 SYNOPSIS
just put the renderer in your gbrowse.conf/MobyServices folder
and it will work.
=head1 DESCRIPTION
This renderer returns HTML that fits between the
<td> tags in a web-page to display the content
of a text_xml (or ontological child of) object.
Without the renderer your browser will ignore the
tags which are not part of the HTML specification.
In consequence the xml document structure, element
names and attributes/values will be invisible in
the result output - which is probably not what
you would expect...
=head1 METHODS
The module has two methods:
=over
( run in 1.818 second using v1.01-cache-2.11-cpan-6aa56a78535 )