my $parent = $n->parentNode();
my @children = $n->childNodes();
my $first = shift @children;
- $parent->replaceChild( $first, $n );
- foreach my $c ( @children ) {
- $parent->insertAfter( $c, $first );
- $first = $c;
+ if( $first ) {
+ $parent->replaceChild( $first, $n );
+ foreach my $c ( @children ) {
+ $parent->insertAfter( $c, $first );
+ $first = $c;
+ }
+ } else {
+ $parent->removeChild( $n );
}
}
# Anchor to mark the end of some apparatus; save its ID.
push( @readings, { 'type' => 'anchor',
'content' => $xn->getAttribute( 'xml:id' ) } );
- } elsif ( $xn->nodeName ne 'note' ) { # Any tag we don't know to disregard
+ } elsif ( $xn->nodeName !~ /^(note|seg)$/ ) { # Any tag we don't know to disregard
print STDERR "Unrecognized tag " . $xn->nodeName . "\n";
}
return @readings;
# Make the path edges
$c->make_witness_paths();
+
+ # Now remove any orphan nodes, and warn that we are doing so.
+ foreach my $v ( $c->sequence->isolated_vertices ) {
+ my $r = $c->reading( $v );
+ print STDERR "Deleting orphan reading $r / " . $r->text;
+ $c->del_reading( $r );
+ }
}
sub _add_wit_path {
my %ac_wits; # Track these for later removal
foreach my $sigil ( map { $_->{'witness'} } @{$table->{'alignment'}} ) {
my $wit;
- if( $tradition->has_witness( $sigil ) {
+ if( $tradition->has_witness( $sigil ) ) {
$wit = $tradition->witness( $sigil );
$wit->is_collated( 1 );
} else {