use strict;
use warnings;
use Encode qw/ decode /;
+use Text::Tradition::Error;
use Text::Tradition::Parser::Util qw/ collate_variants /;
use XML::LibXML;
use XML::LibXML::XPathContext;
warn "Could not find string or file option to parse";
return;
}
-
+
# Second, remove the formatting
my $xpc = XML::LibXML::XPathContext->new( $doc->documentElement );
my @useless = $xpc->findnodes( '//hi' );
}
# Third, write out and reparse to merge the text nodes.
- my $result = decode( $doc->encoding, $doc->toString() );
+ my $enc = $doc->encoding || 'UTF-8';
+ my $result = decode( $enc, $doc->toString() );
my $tei = $parser->parse_string( $result )->documentElement;
+ unless( $tei->nodeName =~ /^tei(corpus)?$/i ) {
+ throw( "Parsed document has non-TEI root element " . $tei->nodeName );
+ }
$xpc = XML::LibXML::XPathContext->new( $tei );
return( $tei, $xpc );
}
}
}
+sub throw {
+ Text::Tradition::Error->throw(
+ 'ident' => 'Parser::CTE error',
+ 'message' => $_[0],
+ );
+}
+
=back
=head1 LICENSE
use warnings;
use Exporter 'import';
use vars qw/ @EXPORT_OK $xpc /;
-
+use Text::Tradition::Error;
use XML::LibXML;
use XML::LibXML::XPathContext;
$edgedata->{$keyid} = $keyname;
}
}
+
+ my @graph_elements = $xpc->findnodes( '/g:graphml/g:graph' );
+ unless( @graph_elements ) {
+ throw( "No graph elements found in graph XML - is this really GraphML?" );
+ }
my @returned_graphs;
- foreach my $graph_el ( $xpc->findnodes( '/g:graphml/g:graph' ) ) {
+ foreach my $graph_el ( @graph_elements ) {
my $graph_hash = { 'nodes' => [],
'edges' => [],
'name' => $graph_el->getAttribute( 'id' ) };
return $data;
}
+sub throw {
+ Text::Tradition::Error->throw(
+ 'ident' => 'Parser::GraphML error',
+ 'message' => $_[0],
+ );
+}
+
=head1 LICENSE
This package is free software and is provided "as is" without express
use strict;
use warnings;
+use Text::Tradition::Error;
use Text::Tradition::Parser::Util qw( collate_variants );
use XML::LibXML;
use XML::LibXML::XPathContext;
return;
}
my $tei = $doc->documentElement();
+ unless( $tei->nodeName =~ /^tei(corpus)?$/i ) {
+ throw( "Parsed document has non-TEI root element " . $tei->nodeName );
+ }
my $xpc = XML::LibXML::XPathContext->new( $tei );
my $ns;
if( $tei->namespaceURI ) {
1;
+sub throw {
+ Text::Tradition::Error->throw(
+ 'ident' => 'Parser::TEI error',
+ 'message' => $_[0],
+ );
+}
+
=head1 BUGS / TODO
=over