fixed recursive_children cvterm function, and added tests for parents and children
[cxgn-corelibs.git] / lib / MOBY / MobyXMLRetriever.pl
blob94be70c283e1ce49555f66c5ddb1ffe3a56d60d1
1 #!/usr/bin/perl -w
2 use XML::LibXML;
3 my $parser = XML::LibXML->new;
5 ## Parsing large CDATA sections is very slow, so replace each
6 ## CDATA section with a placeholder tag before parsing the document.
7 my $xml = '';
9 my @cdata;
10 $xml =~ s{<!\[CDATA\[((?>[^\]]+))\]\]>}
12 push @cdata, $1;
13 '<cdata/>';
14 }eg;
16 my $doc = eval { $parser->parse_string($xml) };
17 if ($@)
19 $@ =~ s/ at \S+ line \d+$//;
20 die $@;
23 ## <document>
24 my $root_node = $doc->getDocumentElement;
26 ## Replace the cdata placeholder tag with a CDATASection node.
27 for my $cdata_node ($root_node->getElementsByTagName('cdata'))
29 $cdata_node->replaceNode(XML::LibXML::CDATASection->new(shift @cdata));