allow either file or string to be passed for parsing
[scpubgit/stemmatology.git] / lib / Text / Tradition / Parser / CTE.pm
index 954a84a..e16a9c7 100644 (file)
@@ -33,12 +33,20 @@ my %sigil_for;  # Save the XML IDs for witnesses.
 my %apps;       # Save the apparatus XML for a given ID.    
 
 sub parse {
-       my( $tradition, $xml_str ) = @_;
+       my( $tradition, $opts ) = @_;
        my $c = $tradition->collation;  # Some shorthand
        
        # First, parse the XML.
        my $parser = XML::LibXML->new();
-       my $doc = $parser->parse_string( $xml_str );
+    my $doc;
+    if( exists $opts->{'string'} ) {
+        $doc = $parser->parse_string( $opts->{'string'} );
+    } elsif ( exists $opts->{'file'} ) {
+        $doc = $parser->parse_file( $opts->{'file'} );
+    } else {
+        warn "Could not find string or file option to parse";
+        return;
+    }
        my $tei = $doc->documentElement();
        my $xpc = XML::LibXML::XPathContext->new( $tei );