[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at pub.open-bio.org
Mon Sep 22 13:25:20 EDT 2003
mwilkinson
Mon Sep 22 12:25:20 EDT 2003
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv20398/Perl/MOBY
Modified Files:
CommonSubs.pm
Log Message:
moving some common subs around so that they are not module-specific
moby-live/Perl/MOBY CommonSubs.pm,1.14,1.15
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm 2003/09/14 18:28:47 1.14
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm 2003/09/22 16:25:20 1.15
@@ -76,6 +76,7 @@
validateNamespaces
isSimpleArticle
isCollectionArticle
+ extractResponseArticles
);
%EXPORT_TAGS =(all => [qw(
getSimpleArticleIDs
@@ -89,6 +90,7 @@
validateNamespaces
isSimpleArticle
isCollectionArticle
+ extractResponseArticles
)]);
@@ -554,4 +556,67 @@
push @lsids, $s?$LSID:undef;
}
return @lsids;
+}
+
+
+=head2 extractResponseArticles
+
+ name : extractResponseArticles
+ function : get the DOM nodes corresponding to individual
+ Simple or Collection outputs from a MOBY Response
+ usage : ($collections, $simples) = extractResponseArticles($node)
+ args : $node - either raw XML or an XML::DOM::Document to be searched
+ returns : an array-ref of Collection article XML::DOM::Node's
+ an array-ref of Simple article XML::DOM::Node's
+
+=cut
+
+
+sub extractResponseArticles {
+ my ($result) = @_;
+ return ([], []) unless $result;
+ my $moby;
+ unless (ref($result) =~ /XML\:\:DOM/){
+ my $parser = new XML::DOM::Parser;
+ my $doc = $parser->parse($result);
+ $moby = $doc->getDocumentElement();
+ } else {
+ $moby = $result->getDocumentElement();
+ }
+ my @objects;
+ my @collections;
+ my @Xrefs;
+ my $success = 0;
+ my $responses = $moby->getElementsByTagName('moby:queryResponse');
+ $responses ||= $moby->getElementsByTagName('queryResponse');
+ foreach my $n(0..($responses->getLength - 1)){
+ my $resp = $responses->item($n);
+ foreach my $response_component($resp->getChildNodes){
+ next unless $response_component->getNodeType == ELEMENT_NODE;
+ if (($response_component->getTagName eq "Simple") || ($response_component->getTagName eq "moby:Simple")){
+
+ my $simples = $resp->getElementsByTagName('Simple');
+ $simples ||=$resp->getElementsByTagName('moby:Simple');
+ next unless $simples->item(0);
+ foreach my $Object($simples->item(0)->getChildNodes) {
+ next unless $Object->getNodeType == ELEMENT_NODE;
+ $success = 1;
+ push @objects,$Object;
+ }
+ } elsif (($response_component->getTagName eq "Collection") || ($response_component->getTagName eq "moby:Collection")){
+ my @objects;
+ foreach my $simple($response_component->getChildNodes){
+ next unless $simple->getNodeType == ELEMENT_NODE;
+ next unless (($simple->getTagName eq "Simple") || ($simple->getTagName eq "moby:Simple"));
+ foreach my $Object($simple->getChildNodes) {
+ next unless $Object->getNodeType == ELEMENT_NODE;
+ $success = 1;
+ push @objects,$Object;
+ }
+ }
+ push @collections, \@objects; #I'm not using collections yet, so we just use Simples.
+ }
+ }
+ }
+ return (\@collections, \@objects);
}
\ No newline at end of file
More information about the MOBY-guts
mailing list