[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Wed Mar 16 22:30:31 UTC 2005


mwilkinson
Wed Mar 16 17:30:31 EST 2005
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv10903/MOBY

Modified Files:
	CommonSubs.pm 
Log Message:
altered getNodeContentWithArticle so that you can get the text content of the root node by leaving off the articleName argument.  This is very useful... honest...

moby-live/Perl/MOBY CommonSubs.pm,1.63,1.64
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -r1.63 -r1.64
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2005/03/14 18:30:57	1.63
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2005/03/16 22:30:31	1.64
@@ -1158,11 +1158,15 @@
                            be the entire mobyData block.
             $tagname     - the tagname (effectively from the Object type ontology),
                            or "Parameter" if you are trying to get secondaries
-            $articleName - the articleName that we are searching for
+            $articleName - the articleName that we are searching for.
+                           to get the content of the primary object, leave
+                           this field blank!
+            
+ returns  : an ARRAY of the stringified text content for each
+            node that matched the tagname/articleName specified; one
+            array element for each matching node.  Newlines are NOT considered
+            new nodes (as they are in normal XML).
             
- returns  : an array of the stringified text content for each
-            node that matched the tagname/articleName specified.
-            note that each line of content is an element of the string.
  notes    : This was written for the purpose of getting the values of
             String, Integer, Float, Date_Time, and other such primitives.
             For example, in the following XML:
@@ -1221,9 +1225,9 @@
              foreach my $article(@articles){
                 my ($type, $DOM) = @{$article};
                 if ($type == SECONDARY){
-                    $cutoff = getNodeContentsWithArticle($DOM, "Parameter", "cutoff");
+                    ($cutoff) = getNodeContentsWithArticle($DOM, "Parameter", "cutoff");
                 } else {
-                   $sequences = getNodeContentWithArticle($DOM, "String", "SequenceString");
+                   @sequences = getNodeContentWithArticle($DOM, "String", "SequenceString");
                 }
              }
            }
@@ -1245,11 +1249,24 @@
 	my @contents;
 	return () unless ref( $node ) =~ /XML::LibXML/;
 	return () unless $element;
-	return () unless $articleName;
+
+    unless ($articleName){  # the request is for root node if no articleName
+        my $resp;
+        foreach my $child($node->childNodes){
+            next unless ($child->nodeType == TEXT_NODE || $child->nodeType == CDATA_SECTION_NODE);
+            $resp .= $child->nodeValue;
+        }
+        push @contents, $resp;
+    	return @contents;
+    }
+
 	my $nodes = $node->getElementsByTagName( $element );
 	unless ( $nodes->get_node( 1 ) ) {
 		$nodes = $node->getElementsByTagName( "moby:$element" );
 	}
+	
+    
+    # if there is an articleName, then get that specific node
 	for ( 1 .. $nodes->size() ) {
 		my $child = $nodes->get_node( $_ );
 		if (




More information about the MOBY-guts mailing list