[MOBY-guts] biomoby commit

Frank Gibbons fgibbons at pub.open-bio.org
Tue Aug 30 15:31:52 UTC 2005


fgibbons
Tue Aug 30 11:31:52 EDT 2005
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv22740/lib/MOBY

Modified Files:
	CommonSubs.pm 
Log Message:
 - A fair bit of re-factoring, along with a few bug-fixes.
 - Re-factoring consisted of 
 	* merging parallel regexps into one; 
	* using short-circuiting '||' to merge several statements into one;
	* extracting repeated code blocks into subroutine (_string_to_DOM)
- Bugs fixed were discovered while running tests :)
	* isSecondaryArticle had typo: "parse( _string" 
	  instead of "parse_string(", which apparently ran fine, 
	  but always failed.
	* validateThisNamespace had an index-error (assumed array started
	  at 1, instead of 0)
- Couple of other things that might have bitten someone in the ass, 
  or maybe not:
	* some regexps checked for "=~ /XML::LibXML/", where regexps have
	the tendency to interpret ':' in their own special way, unless
	escaped.
	* Perl's ref operatore just returns strings, so it's best to compare 
	using 'eq' if you know exactly what the string should look like.
	So a lot of "ref($XML) =~ /array/i" have become "ref($XML) eq 'ARRAY'".
	On the other hand, sometimes it's enough to know that something 
	is a kind of 'XML::LibXML', without knowing exactly what kind,
	so those regexp comparisons are left alone. I also added some 
	namespace stuff in isSimple|Collection|SecondaryArticle, since both
	<moby:Simple> and <Simple> should be considered valid Simples.
 - As for whitespace, I try to respect people's preferences regarding style,
   but I had to reign in some of them, since they wouldn't fit on 
   my 1028x760 monitor in emacs without wrapping a lot 
   (maybe my emacs isn't set up right). Sorry Mark ;)

moby-live/Perl/MOBY CommonSubs.pm,1.66,1.67
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -r1.66 -r1.67
--- /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2005/08/04 09:05:38	1.66
+++ /home/repository/moby/moby-live/Perl/MOBY/CommonSubs.pm	2005/08/30 15:31:52	1.67
@@ -468,7 +468,6 @@
 
 =head2 getArticles
 
- name     : getArticles
  function : get the Simple/Collection/Parameter articles for a single mobyData
  usage    : @articles = getArticles($XML)
  args     : raw XML or XML::LibXML of a queryInput, mobyData, or queryResponse block (e.g. from getInputs)
@@ -479,7 +478,7 @@
             
     e.g.:  @articles = ['name1', $SIMPLE_DOM]
 
-            generated from the following sample XML:
+generated from the following sample XML:
 
                 <mobyData>
                     <Simple articleName='name1'>
@@ -489,7 +488,7 @@
         
     or  :  @articles = ['name1', $COLL_DOM], ['paramname1', $PARAM_DOM]
 
-            generated from the following sample XML:
+generated from the following sample XML:
 
                 <mobyData>
                     <Collection articleName='name1'>
@@ -508,31 +507,22 @@
 =cut
 
 sub getArticles {
-	my ( $moby ) = @_;
-	unless ( ref( $moby ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $moby );
-		$moby = $doc->getDocumentElement();
-	}
-	return undef unless $moby->nodeType == ELEMENT_NODE;
-	return undef
-	  unless (    ( $moby->nodeName =~ /queryInput/ )
-			   || ( $moby->nodeName =~ /queryResponse/ )
-			   || ( $moby->nodeName =~ /mobyData/ ) );
-	my @articles;
-	foreach my $child ( $moby->childNodes )
-	{ # there may be more than one Simple/Collection per input; iterate over them
-		next unless $child->nodeType == ELEMENT_NODE;    # ignore whitespace
-		next
-		  unless (    $child->nodeName =~ /Simple/
-				   || $child->nodeName =~ /Collection/
-				   || $child->nodeName =~ /Parameter/ );
-		my $articleName = $child->getAttribute( 'articleName' );
-		$articleName ||= $child->getAttribute( 'moby:articleName' );
-		push @articles, [ $articleName, $child ]
-		  ; # push the named child DOM elements (which are <Simple> or <Collection>, <Parameter>)
-	}
-	return @articles;    # return them.
+  my ( $moby ) = @_;
+  $moby = _string_to_DOM($moby);
+  return undef
+    unless ( ($moby->nodeType == ELEMENT_NODE)
+	     && ( $moby->nodeName =~ /queryInput|queryResponse|mobyData/ ) );
+  my @articles;
+  foreach my $child ( $moby->childNodes )
+    { # there may be more than one Simple/Collection per input; iterate over them
+      next unless ( ($child->nodeType == ELEMENT_NODE)    # ignore whitespace
+		    && ( $child->nodeName =~ /Simple|Collection|Parameter/ ) );
+      my $articleName = $child->getAttribute( 'articleName' )
+	|| $child->getAttribute( 'moby:articleName' );
+      # push the named child DOM elements (which are <Simple> or <Collection>, <Parameter>)
+      push @articles, [ $articleName, $child ]; 
+    }
+  return @articles;    # return them.
 }
 #################################################
 ##################################
@@ -565,78 +555,66 @@
 
 #Eddie - converted
 sub getSimpleArticleIDs {
-	my ( $desired_namespace, $input_nodes ) = @_;
-	if ( $desired_namespace && !( $input_nodes ) )
-	{    # if called with ONE argument, then these are the input nodes!
-		$input_nodes       = $desired_namespace;
-		$desired_namespace = undef;
-	}
-	$input_nodes = [$input_nodes]
-	  unless ref( $input_nodes ) =~ /ARRAY/;    # be flexible!
-	return undef unless scalar @{$input_nodes};
-	my @input_nodes = @{$input_nodes};
-	my $OS          = MOBY::Client::OntologyServer->new;
-	my ( $s, $m );
-	if ( $desired_namespace ) {
-		( $s, $m, $desired_namespace ) =
-		  $OS->namespaceExists( term => $desired_namespace )
-		  ;    # returns (success, message, lsid)
-		unless ( $s ) {    # bail if not successful
-			print STDERR
-"MOBY::CommonSubs WARNING ** the namespace $desired_namespace does not exist in the MOBY ontology, and is not a valid LSID\n";
-			return undef;
-		}
-	}
-	my @ids;
-	foreach my $in ( @input_nodes ) {
-		next unless $in;
-
-		#$in = "<Simple><Object namespace='' id=''/></Simple>"
-		next unless $in->nodeName =~ /simple/i;    # only allow simples
-		my @simples = $in->childNodes;
-		foreach ( @simples ) {    # $_ = <Object namespace='' id=''/>
-			next unless $_->nodeType == ELEMENT_NODE;
-			if ( $desired_namespace ) {
-				my $ns =
-				  $_->getAttributeNode( 'namespace' )
-				  ;               # get the namespace DOM node
-				$ns = $_->getAttributeNode( 'moby:namespace' )
-				  unless ( $ns );    # perhaps it is namespaced...
-				unless ( $ns )
-				{    # if we don't get it at all, then move on to the next input
-					push @ids,
-					  undef;    # but push an undef onto teh stack in order
-					next;
-				}
-				$ns =
-				  $ns->getValue;    # if we have a namespace, then get its value
-				( $s, $m, $ns ) = $OS->namespaceExists( term => $ns );
-				unless ( $ns eq $desired_namespace )
-				{ # we are registering as working in a particular namespace, so check this
-					push @ids,
-					  undef;    # and push undef onto the stack if it isn't
-					next;
-				}
-			}
-
-			# Now do the same thing for ID's
-			my $id = $_->getAttributeNode( 'id' );
-			$id = $_->getAttributeNode( 'moby:id' ) unless ( $id );
-			unless ( $id ) {
-				push @ids, undef;
-				next;
-			}
-			$id = $id->getValue;
-			unless ( defined $id )
-			{    # it has to have a hope in hell of retrieving something...
-				push @ids,
-				  undef;    # otherwise push undef onto the stack if it isn't
-				next;
-			}
-			push @ids, $id;
-		}
+  my ( $desired_namespace, $input_nodes ) = @_;
+  if ( $desired_namespace && !$input_nodes )
+    {    # if called with ONE argument, then these are the input nodes!
+      $input_nodes       = $desired_namespace;
+      $desired_namespace = undef;
+    }
+  $input_nodes = [$input_nodes]
+    unless ref( $input_nodes ) eq 'ARRAY';    # be flexible!
+  return undef unless scalar @{$input_nodes};
+  my @input_nodes = @{$input_nodes};
+  my $OS          = MOBY::Client::OntologyServer->new;
+  my ( $s, $m );
+  if ( $desired_namespace ) {
+    ( $s, $m, $desired_namespace ) =
+      $OS->namespaceExists( term => $desired_namespace ); # returns (success, message, lsid)
+    unless ( $s ) {    # bail if not successful
+      print STDERR
+	"MOBY::CommonSubs WARNING ** the namespace '$desired_namespace' does not exist in the MOBY ontology, and is not a valid LSID\n";
+      return undef;
+    }
+  }
+  my @ids;
+  foreach my $in ( @input_nodes ) {
+    next unless $in;
+    #$in = "<Simple><Object namespace='' id=''/></Simple>"
+    next unless $in->nodeName =~ /Simple/;    # only allow simples
+    my @simples = $in->childNodes;
+    foreach ( @simples ) {    # $_ = <Object namespace='' id=''/>
+      next unless $_->nodeType == ELEMENT_NODE;
+      if ( $desired_namespace ) {
+	my $ns = $_->getAttributeNode( 'namespace' ) # get the namespace DOM node
+	  || $_->getAttributeNode( 'moby:namespace' );
+	unless ( $ns ) {    # if we don't get it at all, then move on to the next input
+	    push @ids, undef;    # but push an undef onto teh stack in order
+	    next;
+	  }
+	$ns = $ns->getValue;    # if we have a namespace, then get its value
+	( $s, $m, $ns ) = $OS->namespaceExists( term => $ns );
+	unless ( $ns eq $desired_namespace )
+	  { # we are registering as working in a particular namespace, so check this
+	    push @ids, undef;    # and push undef onto the stack if it isn't
+	    next;
+	  }
+      }
+      
+      # Now do the same thing for ID's
+      my $id = $_->getAttributeNode( 'id' ) || $_->getAttributeNode( 'moby:id' );
+      unless ( $id ) {
+	push @ids, undef;
+	next;
+      }
+      $id = $id->getValue;
+      unless ( defined $id ) {    # it has to have a hope in hell of retrieving something...
+	  push @ids, undef;    # otherwise push undef onto the stack if it isn't
+	  next;
 	}
-	return @ids;
+      push @ids, $id;
+    }
+  }
+  return @ids;
 }
 
 =head2 getSimpleArticleNamespaceURI
@@ -656,29 +634,23 @@
 sub getSimpleArticleNamespaceURI {
 
 # pass me a <SIMPLE> input node and I will give you the lsid of the namespace of that input object
-	my ( $input_node ) = @_;
-	return undef unless $input_node;
-	my $OS = MOBY::Client::OntologyServer->new;
-
-	#$input_node = "<Simple><Object namespace='' id=''/></Simple>"
-	my @simples = $input_node->childNodes;
-	foreach ( @simples )
-	{ # $_ = <Object namespace='' id=''/>   # should be just one, so I will return at will from this routine
-		next unless $_->nodeType == ELEMENT_NODE;
-		my $ns =
-		  $_->getAttributeNode( 'namespace' );    # get the namespace DOM node
-		$ns = $_->getAttributeNode( 'moby:namespace' )
-		  unless ( $ns );                         # perhaps it is namespaced...
-		unless ( $ns )
-		{    # if we don't get it at all, then move on to the next input
-			return undef;
-		}
-		my ( $s, $m, $lsid ) =
-		  $OS->namespaceExists( term => $ns->getValue )
-		  ;    # if we have a namespace, then get its value
-		return undef unless $s;
-		return $lsid;
-	}
+  my ( $input_node ) = @_;
+  return undef unless $input_node;
+  my $OS = MOBY::Client::OntologyServer->new;
+  
+  #$input_node = "<Simple><Object namespace='' id=''/></Simple>"
+  my @simples = $input_node->childNodes;
+  foreach ( @simples )
+    { # $_ = <Object namespace='' id=''/>   # should be just one, so I will return at will from this routine
+      next unless $_->nodeType == ELEMENT_NODE;
+      my $ns = $_->getAttributeNode( 'namespace' )     # get the namespace DOM node
+	|| $_->getAttributeNode( 'moby:namespace' );
+	return undef unless ( $ns ); # if we don't get it at all, then move on to the next input
+      my ( $s, $m, $lsid ) =
+	$OS->namespaceExists( term => $ns->getValue );   # if we have a namespace, then get its value
+      return undef unless $s;
+      return $lsid;
+    }
 }
 
 =head2 simpleResponse
@@ -698,46 +670,32 @@
 =cut
 
 sub simpleResponse {
-	my ( $data, $articleName, $qID ) = @_;    # articleName optional
-	$qID = &_getQueryID( $qID )
-	  if ref( $qID ) =~
-	  /XML::LibXML/;    # in case they send the DOM instead of the ID
-	$data        ||= '';    # initialize to avoid uninit value errors
-	$qID         ||= "";
-	$articleName ||= "";
-	if ( $articleName ) {
-		return "
-        <moby:mobyData moby:queryID='$qID'>
-            <moby:Simple moby:articleName='$articleName'>$data</moby:Simple>
-        </moby:mobyData>
-        ";
-	} elsif ( $data ) {
-		return "
+  my ( $data, $articleName, $qID ) = @_;    # articleName optional
+  $qID = &_getQueryID( $qID )
+    if ref( $qID ) =~ /XML\:\:LibXML/;    # in case they send the DOM instead of the ID
+  $data        ||= '';    # initialize to avoid uninit value errors
+  $articleName ||= "";
+  $qID         ||= "";
+  if ( $articleName || $data) { # Linebreaks in XML make it easier for human debuggers to read!
+    return "
         <moby:mobyData moby:queryID='$qID'>
             <moby:Simple moby:articleName='$articleName'>$data</moby:Simple>
         </moby:mobyData>
         ";
-	} else {
-		return "
+  } else {
+    return "
         <moby:mobyData moby:queryID='$qID'/>
 	";
-	}
+  }
 }
 
 #Eddie - converted
 sub _getQueryID {
-	my ( $query ) = @_;
-	unless ( ref( $query ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $query );
-		$query = $doc->getDocumentElement();
-	}
-	return ''
-	  unless (    $query->nodeName =~ /queryInput/
-			   || $query->nodeName =~ /mobyData/ );    #Eddie - unsure
-	my $id = $query->getAttribute( 'queryID' );
-	$id ||= $query->getAttribute( 'moby:queryID' );
-	return $id;
+  my ( $query ) = @_;
+  $query = _string_to_XML($query);
+  return '' unless ( $query->nodeName =~ /queryInput|mobyData/ ); #Eddie - unsure
+  return ($query->getAttribute( 'queryID' ) 
+	  || $query->getAttribute( 'moby:queryID' ));
 }
 
 =head2 collectionResponse
@@ -757,40 +715,40 @@
 =cut
 
 sub collectionResponse {
-	my ( $data, $articleName, $qID ) = @_;    # articleName optional
-	my $content = "";
-	$data ||= [];
-	$qID  ||= '';
-	unless ( ( ref( $data ) =~ /array/i ) && $data->[0] )
-	{    # we're expecting an arrayref as input data,and it must not be empty
-		return "<moby:mobyData moby:queryID='$qID'/>";
-	}
-	foreach ( @{$data} ) {
-		if ( $_ ) {
-			$content .= "
+  my ( $data, $articleName, $qID ) = @_;    # articleName optional
+  my $content = "";
+  $data ||= [];
+  $qID  ||= '';
+  unless ( ( ref($data) eq 'ARRAY' ) && $data->[0] )
+    {    # we're expecting an arrayref as input data,and it must not be empty
+      return "<moby:mobyData moby:queryID='$qID'/>";
+    }
+  foreach ( @{$data} ) {
+    if ( $_ ) {
+      $content .= "
                 <moby:Simple>$_</moby:Simple>
             ";
-		} else {
-			$content .= "
+    } else {
+      $content .= "
                 <moby:Simple/>
             ";
-		}
-	}
-	if ( $articleName ) {
-		return "
+    }
+  }
+  if ( $articleName ) {
+    return "
         <moby:mobyData moby:queryID='$qID'>
             <moby:Collection moby:articleName='$articleName'>
                 $content
             </moby:Collection>
         </moby:mobyData>
         ";
-	} else {
-		return "
+  } else {
+    return "
         <moby:mobyData moby:queryID='$qID'>
             <moby:Collection moby:articleName='$articleName'>$content</moby:Collection>
         </moby:mobyData>
         ";
-	}
+  }
 }
 
 =head2 complexResponse
@@ -810,43 +768,43 @@
 =cut
 
 sub complexResponse {
-	my ( $data, $qID ) = @_;
-	#return 'ERROR:  expected listref [element1, element2, ...] for data' unless ( ref( $data ) =~ /array/i );
-	return "<moby:mobyData moby:queryID='$qID'/>\n" unless ( ref( $data ) =~ /array/i );
-	$qID = &_getQueryID( $qID )
-	  if ref( $qID ) =~ /XML::LibXML/;    # in case they send the DOM instead of the ID
-	my @inputs = @{$data};
-	my $output;
-	$output .= "<moby:mobyData queryID='$qID'>";
-	foreach ( @inputs ) {
-		#return 'ERROR:  expected listref [articleName, XML] for data element' unless ( ref( $_ ) =~ /array/i );
-		return "<moby:mobyData moby:queryID='$qID'/>\n" unless ( ref( $_ ) =~ /array/i );
-		while ( my ( $articleName, $XML ) = splice( @{$_}, 0, 2 ) ) {
-			if ( !( ref( $XML ) =~ /array/i ) ) {
-				$articleName ||= "";
-				$XML         ||= "";
-				if ( ( $XML =~ /\<Value\>/ ) || ( $XML =~ /\<moby\:Value\>/ ) )
-				{
-					$output .=
-"<moby:Parameter moby:articleName='$articleName'>$XML</moby:Parameter>";
-				} else {
-					$output .=
-"<moby:Simple moby:articleName='$articleName'>\n$XML\n</moby:Simple>\n";
-				}
-
-				# need to do this for collections also!!!!!!
-			} elsif ( ref( $XML ) =~ /array/i ) {
-				my @objs = @{$XML};
-				$output .= "<moby:Collection moby:articleName='$articleName'>\n";
-				foreach ( @objs ) {
-					$output .= "<moby:Simple>$_</moby:Simple>\n";
-				}
-				$output .= "</moby:Collection>\n";
-			}
-		}
+  my ( $data, $qID ) = @_;
+  #return 'ERROR:  expected listref [element1, element2, ...] for data' unless ( ref( $data ) =~ /array/i );
+  return "<moby:mobyData moby:queryID='$qID'/>\n" 
+    unless ( ref( $data ) eq 'ARRAY' );
+  $qID = &_getQueryID( $qID )
+    if ref( $qID ) =~ /XML\:\:LibXML/;    # in case they send the DOM instead of the ID
+  my @inputs = @{$data};
+  my $output = "<moby:mobyData queryID='$qID'>";
+  foreach ( @inputs ) {
+    #return 'ERROR:  expected listref [articleName, XML] for data element' unless ( ref( $_ ) =~ /array/i );
+    return "<moby:mobyData moby:queryID='$qID'/>\n" unless ( ref($_) eq 'ARRAY' );
+    while ( my ( $articleName, $XML ) = splice( @{$_}, 0, 2 ) ) {
+      if ( ref($XML) ne 'ARRAY' ) {
+	$articleName ||= "";
+	$XML         ||= "";
+	if ( ( $XML =~ /\<Value\>/ ) || ( $XML =~ /\<moby\:Value\>/ ) )
+	  {
+	    $output .=
+	      "<moby:Parameter moby:articleName='$articleName'>$XML</moby:Parameter>";
+	  } else {
+	    $output .=
+	      "<moby:Simple moby:articleName='$articleName'>\n$XML\n</moby:Simple>\n";
+	  }
+	
+	# need to do this for collections also!!!!!!
+      } elsif ( ref($XML) eq 'ARRAY' ) {
+	my @objs = @{$XML};
+	$output .= "<moby:Collection moby:articleName='$articleName'>\n";
+	foreach ( @objs ) {
+	  $output .= "<moby:Simple>$_</moby:Simple>\n";
 	}
-	$output .= "</moby:mobyData>\n";
-	return $output;
+	$output .= "</moby:Collection>\n";
+      }
+    }
+  }
+  $output .= "</moby:mobyData>\n";
+  return $output;
 }
 
 =head2 responseHeader
@@ -871,19 +829,19 @@
 =cut
 
 sub responseHeader {
-	use HTML::Entities ();
-	my ( $auth, $notes ) = &_rearrange( [qw[AUTHORITY NOTE]], @_ );
-	$auth  ||= "not_provided";
-	$notes ||= "";
-	my $xml =
-	    "<?xml version='1.0' encoding='UTF-8'?>"
-	  . "<moby:MOBY xmlns:moby='http://www.biomoby.org/moby' xmlns='http://www.biomoby.org/moby'>"
-	  . "<moby:mobyContent moby:authority='$auth'>";
-	if ( $notes ) {
-		my $encodednotes = HTML::Entities::encode( $notes );
-		$xml .= "<moby:serviceNotes>$encodednotes</moby:serviceNotes>";
-	}
-	return $xml;
+  use HTML::Entities ();
+  my ( $auth, $notes ) = &_rearrange( [qw[AUTHORITY NOTE]], @_ );
+  $auth  ||= "not_provided";
+  $notes ||= "";
+  my $xml =
+    "<?xml version='1.0' encoding='UTF-8'?>"
+      . "<moby:MOBY xmlns:moby='http://www.biomoby.org/moby' xmlns='http://www.biomoby.org/moby'>"
+	. "<moby:mobyContent moby:authority='$auth'>";
+  if ( $notes ) {
+    my $encodednotes = HTML::Entities::encode( $notes );
+    $xml .= "<moby:serviceNotes>$encodednotes</moby:serviceNotes>";
+  }
+  return $xml;
 }
 
 =head2 responseFooter
@@ -900,7 +858,24 @@
 =cut
 
 sub responseFooter {
-	return "</moby:mobyContent></moby:MOBY>";
+  return "</moby:mobyContent></moby:MOBY>";
+}
+
+
+sub _string_to_DOM {
+# Convert string to DOM.
+# If DOM passed in, just return it (i.e., this should be idempotent)
+# By Frank Gibbons, Aug. 2005
+# Utility subroutine, not for external use (no export), widely used in this package.
+  my $XML = shift;
+  my $moby;
+  return $XML if ( ref($XML) =~ /^XML\:\:LibXML/ );
+
+  my $parser = XML::LibXML->new();
+  my $doc;
+  eval { $doc = $parser->parse_string( $XML ) };
+  die("CommonSubs couldn't parse XML '$XML' because\n\t$@") if $@;
+  return $doc->getDocumentElement();
 }
 
 =head2 getInputs
@@ -918,25 +893,17 @@
 
 #Eddie - converted
 sub getInputs {
-	my ( $XML ) = @_;
-	my $moby;
-	unless ( ref( $XML ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $XML );
-		$moby = $doc->getDocumentElement();
-	}
-	my @queries;
-	foreach my $querytag ( 'queryInput', 'moby:queryInput', 'mobyData',
-						   'moby:mobyData' )
-	{
-		my $x =
-		  $moby->getElementsByTagName( $querytag );    # get the mobyData block
-		for ( 1 .. $x->size() )
-		{    # there may be more than one mobyData per message
-			push @queries, $x->get_node( $_ );
-		}
-	}
-	return @queries;    # return them in the order that they were discovered.
+  my ( $XML ) = @_;
+  my $moby =  _string_to_DOM($XML);
+  my @queries;
+  foreach my $querytag qw( queryInput moby:queryInput mobyData moby:mobyData )
+    {
+      my $x = $moby->getElementsByTagName( $querytag );    # get the mobyData block
+      for ( 1 .. $x->size() ) {    # there may be more than one mobyData per message
+	push @queries, $x->get_node( $_ );
+      }
+    }
+  return @queries;    # return them in the order that they were discovered.
 }
 
 =head2 getInputID
@@ -954,18 +921,12 @@
 =cut
 
 sub getInputID {
-	my ( $XML ) = @_;
-	unless ( ref( $XML ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $XML );
-		$XML = $doc->getDocumentElement();
-	}
-	return ''
-	  unless (    ( $XML->nodeName =~ /queryInput/ )
-			   || ( $XML->nodeName =~ /mobyData/ ) );
-	my $qid = $XML->getAttribute( 'queryID' );
-	$qid ||= $XML->getAttribute( 'moby:queryID' );
-	return defined( $qid ) ? $qid : '';
+  my ( $XML ) = @_;
+  my $moby = _string_to_DOM($XML);
+  return '' unless ( $moby->nodeName =~ /queryInput|mobyData/ );
+  my $qid = $moby->getAttribute( 'queryID' ) 
+    || $moby->getAttribute( 'moby:queryID' );
+  return defined( $qid ) ? $qid : '';
 }
 
 =head2 getArticlesAsObjects
@@ -982,38 +943,29 @@
 
 #Eddie - converted
 sub getArticlesAsObjects {
-	my ( $moby ) = @_;
-	unless ( ref( $moby ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $moby );
-		$moby = $doc->getDocumentElement();
-	}
-	return undef unless $moby->nodeType == ELEMENT_NODE;
-	return undef
-	  unless (    ( $moby->nodeName =~ /queryInput/ )
-			   || ( $moby->nodeName =~ /queryResponse/ )
-			   || ( $moby->nodeName =~ /mobyData/ ) );
-	my @articles;
-	foreach my $child ( $moby->childNodes )
-	{ # there may be more than one Simple/Collection per input; iterate over them
-		next unless $child->nodeType == ELEMENT_NODE;    # ignore whitespace
-		next
-		  unless (    $child->nodeName =~ /Simple/
-				   || $child->nodeName =~ /Collection/
-				   || $child->nodeName =~ /Parameter/ );
-		my $object;
-		if ( $child->nodeName =~ /Simple/ ) {
-			$object = MOBY::Client::SimpleArticle->new( XML_DOM => $child );
-		} elsif ( $child->nodeName =~ /Collection/ ) {
-			$object = MOBY::Client::CollectionArticle->new( XML_DOM => $child );
-		} elsif ( $child->nodeName =~ /Parameter/ ) {
-			$object = MOBY::Client::SecondaryArticle->new( XML_DOM => $child );
-		}
-		next unless $object;
-		push @articles, $object
-		  ;    # take the child elements, which are <Simple/> or <Collection/>
-	}
-	return @articles;    # return them.
+  my ( $moby ) = @_;
+  $moby = _string_to_DOM($moby);
+  return undef unless $moby->nodeType == ELEMENT_NODE;
+  return undef
+    unless ($moby->nodeName =~ /queryInput|queryResponse|mobyData/);
+  my @articles;
+  foreach my $child ( $moby->childNodes )
+    { # there may be more than one Simple/Collection per input; iterate over them
+      next unless $child->nodeType == ELEMENT_NODE;    # ignore whitespace
+      next
+	unless ( $child->nodeName =~ /Simple|Collection|Parameter/ );
+      my $object;
+      if ( $child->nodeName =~ /Simple/ ) {
+	$object = MOBY::Client::SimpleArticle->new( XML_DOM => $child );
+      } elsif ( $child->nodeName =~ /Collection/ ) {
+	$object = MOBY::Client::CollectionArticle->new( XML_DOM => $child );
+      } elsif ( $child->nodeName =~ /Parameter/ ) {
+	$object = MOBY::Client::SecondaryArticle->new( XML_DOM => $child );
+      }
+      next unless $object;
+      push @articles, $object;  # take the child elements, which are <Simple/> or <Collection/>
+    }
+  return @articles;    # return them.
 }
 
 =head2 getCollectedSimples
@@ -1027,23 +979,18 @@
 =cut
 
 sub getCollectedSimples {
-	my ( $moby ) = @_;
-	unless ( ref( $moby ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $moby );
-		$moby = $doc->getDocumentElement();
-	}
-	return undef unless $moby->nodeType == ELEMENT_NODE;
-	return undef unless ( $moby->nodeName =~ /Collection/ );
-	my @articles;
-	foreach my $child ( $moby->childNodes )
-	{ # there may be more than one Simple/Collection per input; iterate over them
-		next unless $child->nodeType == ELEMENT_NODE;    # ignore whitespace
-		next unless ( $child->nodeName =~ /Simple/ );
-		push @articles, $child
-		  ;    # take the child elements, which are <Simple/> or <Collection/>
-	}
-	return ( @articles );    # return them.
+  my ( $moby ) = @_;
+  $moby = _string_to_DOM($moby);
+  return undef unless $moby->nodeType == ELEMENT_NODE;
+  return undef unless ( $moby->nodeName =~ /Collection$/ );
+  my @articles;
+  foreach my $child ( $moby->childNodes )
+    { # there may be more than one Simple/Collection per input; iterate over them
+      next unless $child->nodeType == ELEMENT_NODE;    # ignore whitespace
+      next unless ( $child->nodeName =~ /Simple$/ );
+      push @articles, $child; # take the child elements, which are <Simple/> or <Collection/>
+    }
+  return ( @articles );    # return them.
 }
 
 =head2 getInputArticles
@@ -1059,7 +1006,7 @@
             i.e.:  @queries = ([$SIMPLE_DOM_NODE], [$SIMPLE_DOM_NODE2])
             or  :  @queries = ([$COLLECTION_DOM_NODE], [$COLLECTION_DOM_NODE2])
             
-            the former is generated from the following XML:
+The former is generated from the following XML:
             
                 ...
               <moby:mobyContent>
@@ -1080,30 +1027,25 @@
 
 #Eddie - converted
 sub getInputArticles {
-	my ( $moby ) = @_;
-	unless ( ref( $moby ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $moby );
-		$moby = $doc->getDocumentElement();
-	}
-	my $x;
-	foreach ( 'queryInput', 'moby:queryInput', 'mobyData', 'moby:mobyData' ) {
-		$x = $moby->getElementsByTagName( $_ );    # get the mobyData block
-		last if $x->get_node( 1 );
-	}
-	return undef unless $x->get_node( 1 );   # in case there was no match at all
-	my @queries;
-	for ( 1 .. $x->size() ) {  # there may be more than one mobyData per message
-		my @this_query;
-		foreach my $child ( $x->get_node( $_ )->childNodes )
-		{ # there may be more than one Simple/Collection per input; iterate over them
-			next unless $child->nodeType == ELEMENT_NODE;    # ignore whitespace
-			push @this_query, $child
-			  ;  # take the child elements, which are <Simple/> or <Collection/>
-		}
-		push @queries, \@this_query;
-	}
-	return @queries;    # return them in the order that they were discovered.
+  my ( $moby ) = @_;
+  $moby = _string_to_DOM($moby);
+  my $x;
+  foreach ( 'queryInput', 'moby:queryInput', 'mobyData', 'moby:mobyData' ) {
+    $x = $moby->getElementsByTagName( $_ );    # get the mobyData block
+    last if $x->get_node( 1 );
+  }
+  return undef unless $x->get_node( 1 );   # in case there was no match at all
+  my @queries;
+  for ( 1 .. $x->size() ) {  # there may be more than one mobyData per message
+    my @this_query;
+    foreach my $child ( $x->get_node( $_ )->childNodes )
+      { # there may be more than one Simple/Collection per input; iterate over them
+	next unless $child->nodeType == ELEMENT_NODE;    # ignore whitespace
+	push @this_query, $child;  # take the child elements, which are <Simple/> or <Collection/>
+      }
+    push @queries, \@this_query;
+  }
+  return @queries;    # return them in the order that they were discovered.
 }
 
 =head2 isSimpleArticle
@@ -1118,17 +1060,13 @@
 
 #Eddie - converted
 sub isSimpleArticle {
-	my ( $DOM ) = @_;
-	unless ( ref( $DOM ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc;
-		eval { $doc = $parser->parse_string( $DOM ); };
-		return 0 if ( $@ );
-		$DOM = $doc->getDocumentElement();
-	}
-	$DOM = $DOM->getDocumentElement if ( $DOM->isa( "XML::LibXML::Document" ) );
-	return 1 if ( $DOM->nodeName =~ /Simple/ );
-	return 0;
+  my ( $DOM ) = @_;
+  eval { $DOM = _string_to_DOM($DOM) };
+  if ($@) {
+    return 0;
+  }
+  $DOM = $DOM->getDocumentElement if ( $DOM->isa( "XML::LibXML::Document" ) );
+  return ($DOM->nodeName =~ /^(moby:|)Simple$/) ? 1 : 0; #Optional 'moby:' namespace prefix
 }
 
 =head2 isCollectionArticle
@@ -1143,17 +1081,11 @@
 
 #Eddie - converted
 sub isCollectionArticle {
-	my ( $DOM ) = @_;
-	unless ( ref( $DOM ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc;
-		eval { $doc = $parser->parse_string( $DOM ); };
-		return 0 if ( $@ );
-		$DOM = $doc->getDocumentElement();
-	}
-	$DOM = $DOM->getDocumentElement if ( $DOM->isa( "XML::LibXML::Document" ) );
-	return 1 if ( $DOM->nodeName =~ /Collection/ );
-	return 0;
+  my ( $DOM ) = @_;
+  eval {$DOM = _string_to_DOM($DOM) };
+  return 0 if $@;
+  $DOM = $DOM->getDocumentElement if ( $DOM->isa( "XML::LibXML::Document" ) );
+  return ( $DOM->nodeName =~ /^(moby\:|)Collection$/ ) ? 1 : 0; #Optional 'moby:' prefix
 }
 
 =head2 isSecondaryArticle
@@ -1168,19 +1100,15 @@
 
 #Eddie - converted
 sub isSecondaryArticle {
-	my ( $DOM ) = @_;
-	unless ( ref( $DOM ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc;
-		eval { $doc = $parser->parse( _string $DOM); };
-		return 0 if ( $@ );
-		$DOM = $doc->getDocumentElement();
-	}
-	$DOM = $DOM->getDocumentElement if ( $DOM->isa( "XML::LibXML::Document" ) );
-	return 1 if ( $DOM->nodeName =~ /Parameter/ );
-	return 0;
+  my ( $XML ) = @_;
+  my $DOM;
+  eval {$DOM = _string_to_DOM($XML)} ;
+  return 0 if $@;
+  $DOM = $DOM->getDocumentElement if ( $DOM->isa( "XML::LibXML::Document" ) );
+  return ($DOM->nodeName =~ /^(moby\:|)Parameter$/) ? 1 : 0; #Optional 'moby:' prefix
 }
 
+
 =head2 extractRawContent
 
  name     : extractRawContent
@@ -1193,14 +1121,14 @@
 =cut
 
 sub extractRawContent {
-	my ( $article ) = @_;
-	return "" unless $article;
-	return "" unless ref( $article ) =~ /XML::LibXML/;
-	my $response;
-	foreach ( $article->childNodes ) {
-		$response .= $_->toString;
-	}
-	return $response;
+  my ( $article ) = @_;
+  return "" unless ( $article || (ref( $article ) =~ /XML\:\:LibXML/) );
+  my $response;
+  foreach ( $article->childNodes ) {
+    $response .= $_->toString;
+  }
+  print STDERR "RESPONSE = $response\n";
+  return $response;
 }
 
 =head2 getNodeContentWithArticle
@@ -1226,7 +1154,9 @@
             
  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:
+
+For example, in the following XML:
+
              ...
              ...
              <moby:mobyContent>
@@ -1242,12 +1172,13 @@
              ...
              ...
              
-            would be analysed as follows:
-              
+would be analysed as follows:
+
               # get $input - e.g. from genericServiceInputParser or complexServiceInputParser
               @sequences = getNodeContentWithArticle($input, "String", "SequenceString");
 
-            For Parameters, such as the following
+For Parameters, such as the following
+
              ...
              ...
              <moby:mobyContent>
@@ -1265,9 +1196,9 @@
              </moby:mobyContent>
              ...
              ...
-            
-            You would parse it as follows:
-            
+
+You would parse it as follows:
+
               # get $input - e.g. from genericServiceInputParser or complexServiceInputParser
               @sequences = getNodeContentWithArticle($input, "String", "SequenceString");
               @cutoffs = getNodeContentWithArticle($input, "Parameter", "cutoff");
@@ -1293,82 +1224,74 @@
 
 #Eddie - converted
 sub getNodeContentWithArticle {
-
-# give me a DOM, a TagName, an articleName and I will return you the content
-# of that node **as a string** (beware if there are additional XML tags in there!)
-# this is meant for MOBYesque PRIMITIVES - things like:
-# <String articleName="SeuqenceString">TAGCTGATCGAGCTGATGCTGA</String>
-# call _getNodeContentsWithAttribute($DOM_NODE, "String", "SequenceString")
-# and I will return "TACGATGCTAGCTAGCGATCGG"
-# Caveat Emptor - I will NOT chop off leading and trailing whitespace or
-# carriage returns, as these might be meaningful!
-	my ( $node, $element, $articleName ) = @_;
-	my @contents;
-	return () unless ref( $node ) =~ /XML::LibXML/;
-	return () unless $element;
-
-    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;
+  # give me a DOM, a TagName, an articleName and I will return you the content
+  # of that node **as a string** (beware if there are additional XML tags in there!)
+  # this is meant for MOBYesque PRIMITIVES - things like:
+  # <String articleName="SequenceString">TAGCTGATCGAGCTGATGCTGA</String>
+  # call _getNodeContentsWithAttribute($DOM_NODE, "String", "SequenceString")
+  # and I will return "TACGATGCTAGCTAGCGATCGG"
+  # Caveat Emptor - I will NOT chop off leading and trailing whitespace or
+  # carriage returns, as these might be meaningful!
+  my ( $node, $element, $articleName ) = @_;
+  my @contents;
+  return () unless ( (ref( $node ) =~ /XML\:\:LibXML/) &&  $element);
+
+  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;
     }
-
-	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 (
-			 (
-			      ( $child->getAttribute( "articleName" ) )
-			   && ( ( $child->getAttribute( "articleName" ) eq $articleName ) )
-			 )
-			 || (
-				  ( $child->getAttribute( "moby:articleName" ) )
-				  && (
-					   (
-						 $child->getAttribute( "moby:articleName" ) eq
-						 $articleName
-					   )
-				  )
-			 )
-		  )
-		{
-
-# now we have a valid child, get the content... stringified... regardless of what it is
-			if ( isSecondaryArticle( $child ) ) {
-				my $resp;
-				my $valuenodes = $child->getElementsByTagName( 'Value' );
-				unless ( $valuenodes->get_node( 1 ) ) {
-					$valuenodes = $child->getElementsByTagName( "moby:Value" );
-				}
-				for ( 1 .. $valuenodes->size() ) {
-					my $valuenode = $valuenodes->get_node( $_ );
-					foreach my $amount ( $valuenode->childNodes ) {
-						next unless ($amount->nodeType == TEXT_NODE || $amount->nodeType == CDATA_SECTION_NODE);
-						$resp .= $amount->nodeValue;
-					}
-				}
-				push @contents, $resp;
-			} else {
-				my $resp;
-				foreach ( $child->childNodes ) {
-					next unless ($_->nodeType == TEXT_NODE || $_->nodeType == CDATA_SECTION_NODE);
-					$resp .= $_->nodeValue;
-				}
-				push @contents, $resp;
-			}
-		}
+    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 (
+	( $child->getAttribute("articleName") 
+	  && ( $child->getAttribute("articleName") eq $articleName )
+	)
+	|| ( $child->getAttribute("moby:articleName") 
+	     && ( $child->getAttribute("moby:articleName") eq $articleName )
+	   )
+       )
+      {
+	# now we have a valid child, get the content... stringified... regardless of what it is
+	if ( isSecondaryArticle( $child ) ) {
+	  my $resp;
+	  my $valuenodes = $child->getElementsByTagName('Value');
+	  unless ( $valuenodes->get_node( 1 ) ) {
+	    $valuenodes = $child->getElementsByTagName("moby:Value");
+	  }
+	  for ( 1 .. $valuenodes->size() ) {
+	    my $valuenode = $valuenodes->get_node( $_ );
+	    foreach my $amount ( $valuenode->childNodes ) {
+	      next unless ($amount->nodeType == TEXT_NODE
+			   || $amount->nodeType == CDATA_SECTION_NODE);
+	      $resp .= $amount->nodeValue;
+	    }
+	  }
+	  push @contents, $resp;
+	} else {
+	  my $resp;
+	  foreach ( $child->childNodes ) {
+	    next unless ($_->nodeType == TEXT_NODE
+			 || $_->nodeType == CDATA_SECTION_NODE);
+	    $resp .= $_->nodeValue;
+	  }
+	  push @contents, $resp;
 	}
-	return @contents;
+      }
+  }
+  return @contents;
 }
 
 =head2 validateNamespaces
@@ -1384,17 +1307,16 @@
 =cut
 
 sub validateNamespaces {
-
-	# give me a list of namespaces and I will return the LSID's in order
-	# I return undef in that list position if the namespace is invalid
-	my ( @namespaces ) = @_;
-	my $OS = MOBY::Client::OntologyServer->new;
-	my @lsids;
-	foreach ( @namespaces ) {
-		my ( $s, $m, $LSID ) = $OS->namespaceExists( term => $_ );
-		push @lsids, $s ? $LSID : undef;
-	}
-	return @lsids;
+  # give me a list of namespaces and I will return the LSID's in order
+  # I return undef in that list position if the namespace is invalid
+  my ( @namespaces ) = @_;
+  my $OS = MOBY::Client::OntologyServer->new;
+  my @lsids;
+  foreach ( @namespaces ) {
+    my ( $s, $m, $LSID ) = $OS->namespaceExists( term => $_ );
+    push @lsids, $s ? $LSID : undef;
+  }
+  return @lsids;
 }
 
 =head2 validateThisNamespace
@@ -1405,22 +1327,14 @@
  args     : ordered list of the namespace of interest and the list of valid NS's
  returns  : boolean
 
-
 =cut
 
 sub validateThisNamespace {
-	my ( $ns, @namespaces ) = @_;
-	return 1
-	  unless scalar @namespaces
-	  ;    # if you don't give me a list, I assume everything is valid...
-	if ( ref( $namespaces[1] ) =~ /ARRAY/ ) {
-		@namespaces = @{ $namespaces[1] };
-	}      # if you send me an arrayref I should be kind... DWIM!
-	foreach ( @namespaces ) {
-		next unless $_;
-		return 1 if $ns eq $_;
-	}
-	return 0;
+  my ( $ns, @namespaces ) = @_;
+  return 1 unless scalar @namespaces; # if you don't give me a list, I assume everything is valid...
+  @namespaces = @{$namespaces[0]}  # if you send me an arrayref I should be kind... DWIM!
+    if ( ref $namespaces[0] eq 'ARRAY' );
+  return grep /$ns/, @namespaces;
 }
 
 =head2 getResponseArticles (a.k.a. extractResponseArticles)
@@ -1507,37 +1421,24 @@
 
 #Eddie - converted
 sub getServiceNotes {
-	my ( $result ) = @_;
-	return ( "" ) unless $result;
-	my $moby;
-	unless ( ref( $result ) =~ /XML\:\:LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $result );
-		$moby = $doc->getDocumentElement();
-	} else {
-		$moby = $result->getDocumentElement();
-	}
-	my @objects;
-	my @collections;
-	my @Xrefs;
-	my $success   = 0;
-	my $responses = $moby->getElementsByTagName( 'moby:serviceNotes' );
-	$responses ||= $moby->getElementsByTagName( 'serviceNotes' );
-	my $content;
-
-	foreach my $n ( 1 .. ( $responses->size() ) ) {
-		my $resp = $responses->get_node( $n );
-		foreach my $response_component ( $resp->childNodes ) {
-
-			#            $content .= $response_component->toString;
-			$content .= $response_component->nodeValue
-			  if ( $response_component->nodeType == TEXT_NODE );
-        	$content .= $response_component->nodeValue
-			  if ( $response_component->nodeType == CDATA_SECTION_NODE );
-            
-		}
-	}
-	return ( $content );
+  my ( $result ) = @_;
+  return ( "" ) unless $result;
+  my $moby = _string_to_DOM($result);
+
+  my $responses = $moby->getElementsByTagName( 'moby:serviceNotes' )
+    || $moby->getElementsByTagName( 'serviceNotes' );
+  my $content;
+  foreach my $n ( 1 .. ( $responses->size() ) ) {
+    my $resp = $responses->get_node( $n );
+    foreach my $response_component ( $resp->childNodes ) {
+      #            $content .= $response_component->toString;
+      $content .= $response_component->nodeValue
+	if ( $response_component->nodeType == TEXT_NODE );
+      $content .= $response_component->nodeValue
+	if ( $response_component->nodeType == CDATA_SECTION_NODE );
+    }
+  }
+  return ( $content );
 }
 
 =head2 getCrossReferences
@@ -1568,40 +1469,34 @@
 
 #Eddie - converted
 sub getCrossReferences {
-	my ( $XML ) = @_;
-	unless ( ref( $XML ) =~ /XML::LibXML/ ) {
-		my $parser = XML::LibXML->new();
-		my $doc    = $parser->parse_string( $XML );
-		$XML = $doc->getDocumentElement();
-	}
-	my @xrefs;
-	my @XREFS;
-	my @simples;
-	return @XREFS if ( $XML->nodeName =~ /Collection/ );
-	if ( $XML->nodeName =~ /Simple/ ) {
-		foreach my $child ( $XML->childNodes ) {
-			next unless $child->nodeType == ELEMENT_NODE;
-			$XML = $child;
-			last;    # enforce proper MOBY message structure
-		}
-	}
-	foreach ( $XML->childNodes ) {
-		next unless $_->nodeType == ELEMENT_NODE;
-		next unless $_->nodeName =~ /CrossReference/;
-		foreach my $xref ( $_->childNodes ) {
-			next unless $xref->nodeType == ELEMENT_NODE;
-			next
-			  unless (    $xref->nodeName =~ /Xref/
-					   || $xref->nodeName =~ /Object/ );
-			push @xrefs, $xref;
-		}
-	}
-	foreach ( @xrefs ) {
-		my $x = &_makeXrefType( $_ ) if $_->nodeName =~ /Xref/;
-		$x = &_makeObjectType( $_ ) if $_->nodeName =~ /Object/;
-		push @XREFS, $x if $x;
-	}
-	return @XREFS;
+  my ( $XML ) = @_;
+  $XML = _string_to_DOM($XML);
+  my @xrefs;
+  my @XREFS;
+  return () if ( $XML->nodeName =~ /Collection/ );
+  if ( $XML->nodeName =~ /Simple/ ) {
+    foreach my $child ( $XML->childNodes ) {
+      next unless $child->nodeType == ELEMENT_NODE;
+      $XML = $child;
+      last;    # enforce proper MOBY message structure
+    }
+  }
+  foreach ( $XML->childNodes ) {
+    next unless (($_->nodeType == ELEMENT_NODE)
+		 || ($_->nodeName =~ /CrossReference/) );
+    foreach my $xref ( $_->childNodes ) {
+      next unless ( ($xref->nodeType == ELEMENT_NODE)
+		    || ($xref->nodeName =~ /Xref|Object/) );
+      push @xrefs, $xref;
+    }
+  }
+  foreach ( @xrefs ) {
+    my $x;
+    if ($_->nodeName =~ /Xref/) { $x = &_makeXrefType( $_ ) }
+    elsif ($_->nodeName =~ /Object/) { $x = &_makeObjectType( $_ ) }
+    push @XREFS, $x if $x;
+  }
+  return @XREFS;
 }
 
 =head2 whichDeepestParentObject
@@ -1655,51 +1550,51 @@
 
 #Eddie - converted
 sub _makeXrefType {
-	my ( $xref ) = @_;
-	my $ns = $xref->getAttributeNode( 'namespace' );
-	$ns = $xref->getAttributeNode( 'moby:namespace' ) unless $ns;
-	return undef unless $ns;
-	my $id = $xref->getAttributeNode( 'id' );
-	$id = $xref->getAttributeNode( 'moby:id' ) unless $id;
-	return undef unless $id;
-	my $xr = $xref->getAttributeNode( 'xref_type' );
-	$xr = $xref->getAttributeNode( 'moby:xref_type' ) unless $xr;
-	return undef unless $xr;
-	my $ec = $xref->getAttributeNode( 'evidence_code' );
-	$ec = $xref->getAttributeNode( 'moby:evidence_code' ) unless $ec;
-	return undef unless $ec;
-	my $au = $xref->getAttributeNode( 'authURI' );
-	$au = $xref->getAttributeNode( 'moby:authURI' ) unless $au;
-	return undef unless $au;
-	my $sn = $xref->getAttributeNode( 'serviceName' );
-	$sn = $xref->getAttributeNode( 'moby:serviceName' ) unless $sn;
-	return undef unless $sn;
-	my $XREF = MOBY::CrossReference->new(
-										  type          => "xref",
-										  namespace     => $ns->getValue,
-										  id            => $id->getValue,
-										  authURI       => $au->getValue,
-										  serviceName   => $sn->getValue,
-										  evidence_code => $ec->getValue,
-										  xref_type     => $xr->getValue
-	);
-	return $XREF;
+  my ( $xref ) = @_;
+  my $ns = $xref->getAttributeNode( 'namespace' )
+    || $xref->getAttributeNode( 'moby:namespace' );
+  return undef unless $ns;
+  my $id = $xref->getAttributeNode( 'id' ) 
+    || $xref->getAttributeNode( 'moby:id' );
+  return undef unless $id;
+  my $xr = $xref->getAttributeNode( 'xref_type' )
+    || $xref->getAttributeNode( 'moby:xref_type' );
+  return undef unless $xr;
+  my $ec = $xref->getAttributeNode( 'evidence_code' )
+    || $xref->getAttributeNode( 'moby:evidence_code' );
+  return undef unless $ec;
+  my $au = $xref->getAttributeNode( 'authURI' )
+    || $xref->getAttributeNode( 'moby:authURI' );
+  return undef unless $au;
+  my $sn = $xref->getAttributeNode( 'serviceName' )
+    || $xref->getAttributeNode( 'moby:serviceName' );
+  return undef unless $sn;
+  my $XREF = MOBY::CrossReference->new(
+				       type          => "xref",
+				       namespace     => $ns->getValue,
+				       id            => $id->getValue,
+				       authURI       => $au->getValue,
+				       serviceName   => $sn->getValue,
+				       evidence_code => $ec->getValue,
+				       xref_type     => $xr->getValue
+				      );
+  return $XREF;
 }
 
 #Eddie - converted
 sub _makeObjectType {
-	my ( $xref ) = @_;
-	my $ns = $xref->getAttributeNode( 'namespace' );
-	$ns = $xref->getAttributeNode( 'moby:namespace' ) unless $ns;
-	return undef unless $ns;
-	my $id = $xref->getAttributeNode( 'id' );
-	$id = $xref->getAttributeNode( 'moby:id' ) unless $id;
-	return undef unless $id;
-	my $XREF = MOBY::CrossReference->new(
-										  type      => "object",
-										  namespace => $ns->getValue,
-										  id        => $id->getValue,
-	);
+  my ( $xref ) = @_;
+  my $ns = $xref->getAttributeNode( 'namespace' )
+    || $xref->getAttributeNode( 'moby:namespace' );
+  return undef unless $ns;
+  my $id = $xref->getAttributeNode( 'id' )
+    || $xref->getAttributeNode( 'moby:id' );
+  return undef unless $id;
+  my $XREF = MOBY::CrossReference->new(
+				       type      => "object",
+				       namespace => $ns->getValue,
+				       id        => $id->getValue,
+				      );
 }
 
 # _rearrange stolen from BioPerl's Bio::RootI.pm




More information about the MOBY-guts mailing list