| 1 | # /=====================================================================\ # | ||||||||||||||||||||||||||||
| 2 | # | LaTeXML::Common::XML::Parser | # | ||||||||||||||||||||||||||||
| 3 | # | XML Parser (wrapper for XML::LibXML | # | ||||||||||||||||||||||||||||
| 4 | # |=====================================================================| # | ||||||||||||||||||||||||||||
| 5 | # | Part of LaTeXML: | # | ||||||||||||||||||||||||||||
| 6 | # | Public domain software, produced as part of work done by the | # | ||||||||||||||||||||||||||||
| 7 | # | United States Government & not subject to copyright in the US. | # | ||||||||||||||||||||||||||||
| 8 | # |---------------------------------------------------------------------| # | ||||||||||||||||||||||||||||
| 9 | # | Bruce Miller <bruce.miller@nist.gov> #_# | # | ||||||||||||||||||||||||||||
| 10 | # | http://dlmf.nist.gov/LaTeXML/ (o o) | # | ||||||||||||||||||||||||||||
| 11 | # \=========================================================ooo==U==ooo=/ # | ||||||||||||||||||||||||||||
| 12 | package LaTeXML::Common::XML::Parser; | ||||||||||||||||||||||||||||
| 13 | 29 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 29 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 29 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub new { | ||||||||||||||||||||||||||||
| 18 | 0 | ▶ | my ($class) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | my $parser = XML::LibXML->new(); | |||||||||||||||||||||||||||
| 20 | 0 | $parser->validation(0); | |||||||||||||||||||||||||||
| 21 | 0 | return bless { parser => $parser }, $class; } | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub parseFile { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my ($self, $file) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parseFile: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | LaTeXML::Common::XML::initialize_catalogs(); | |||||||||||||||||||||||||||
| 26 | # LaTeXML::Common::XML::initialize_input_callbacks($$self{parser}); | ||||||||||||||||||||||||||||
| 27 | 0 | return $$self{parser}->parse_file($file); } | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub parseString { | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parseString: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 0 | return $$self{parser}->parse_string($string); } | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | sub parseChunk { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | my ($self, $string) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parseChunk: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | my $hasxmlns = $string =~ /\Wxml:id\W/; | |||||||||||||||||||||||||||
| 36 | # print STDERR "\nFISHY!!\n" if $hasxmlns; | ||||||||||||||||||||||||||||
| 37 | 0 | my $xml = $$self{parser}->parse_xml_chunk($string); | |||||||||||||||||||||||||||
| 38 | # Simplify, if we get a single node Document Fragment. | ||||||||||||||||||||||||||||
| 39 | #[which we, apparently, always do] | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($xml && (ref $xml eq 'XML::LibXML::DocumentFragment')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$xml and ref $xml eq "XML::LibXML::DocumentFragment"
MC/DC0%0/2
$xml and ref $xml eq "XML::LibXML::DocumentFragment"
$xml
ref $xml eq "XML::LibXML::DocumentFragment"
Truth table0%0/3
A and B
A= $xmlB= ref $xml eq "XML::LibXML::DocumentFragment"
| |||||||||||||||||||||||||||||
| 41 | 0 | my @k = $xml->childNodes; | |||||||||||||||||||||||||||
| 42 | 0 | ▶ | $xml = $k[0] if (scalar(@k) == 1); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | # $xml = $xml->cloneNode(1); | ||||||||||||||||||||||||||||
| 44 | #### | ||||||||||||||||||||||||||||
| 45 | # In 1.58, the prefix for the XML_NS, which should be DEFINED to be "xml" | ||||||||||||||||||||||||||||
| 46 | # is sometimes unbound, leading to mysterious segfaults!!! | ||||||||||||||||||||||||||||
| 47 | ### if (($xml_libxml_version < 1.59) && $hasxmlns) { | ||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (($LaTeXML::Common::XML::xml_libxml_version < 1.59) && $hasxmlns) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$LaTeXML::Common::XML::xml_libxml_version < "1.59" and $hasxmlns
MC/DC0%0/2
$LaTeXML::Common::XML::xml_libxml_version < "1.59" and $hasxmlns
$LaTeXML::Common::XML::xml_libxml_version < "1.59"
$hasxmlns
Truth table0%0/3
A and B
A= $LaTeXML::Common::XML::xml_libxml_version < "1.59"B= $hasxmlns
| |||||||||||||||||||||||||||||
| 49 | #print STDERR "Patchup...\n"; | ||||||||||||||||||||||||||||
| 50 | # Re-create all xml:id entrys, hopefully with correct NS! | ||||||||||||||||||||||||||||
| 51 | # We assume all id are, in fact, xml:id, | ||||||||||||||||||||||||||||
| 52 | # because we seemingly can't probe the namespace! | ||||||||||||||||||||||||||||
| 53 | 0 | foreach my $attr ($xml->findnodes("descendant-or-self::*/attribute::*[local-name()='id']")) { | |||||||||||||||||||||||||||
| 54 | 0 | my $element = $attr->parentNode; | |||||||||||||||||||||||||||
| 55 | 0 | my $id = $attr->getValue(); | |||||||||||||||||||||||||||
| 56 | #print STDERR "RESET ID: $id\n"; | ||||||||||||||||||||||||||||
| 57 | 0 | $attr->unbindNode(); | |||||||||||||||||||||||||||
| 58 | 0 | $element->setAttributeNS($LaTeXML::Common::XML::XML_NS, 'id', $id); } | |||||||||||||||||||||||||||
| 59 | # print STDERR "\nXML: ".$xml->toString."\n"; | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 0 | return $xml; } | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | #====================================================================== | ||||||||||||||||||||||||||||
| 64 | 29 | 1; | |||||||||||||||||||||||||||