Index: /main/trunk/greenstone2/perllib/doc.pm
===================================================================
--- /main/trunk/greenstone2/perllib/doc.pm	(revision 32511)
+++ /main/trunk/greenstone2/perllib/doc.pm	(revision 32512)
@@ -540,5 +540,5 @@
 		    print STDERR "doc::set_OID could not write to $filename\n";
 		} else {
-		    my $doc_text = &docprint::get_section_xml($self, $self->get_top_section());
+		    my $doc_text = &docprint::get_section_xml($self);
 		    print OUTFILE $doc_text;
 		    close (OUTFILE);
@@ -561,5 +561,5 @@
     if (!defined $OID) 
     {
-	my $hash_text = &docprint::get_section_xml($self, $self->get_top_section());
+	my $hash_text = &docprint::get_section_xml($self);
 	my $hash_len = length($hash_text);
 
Index: /main/trunk/greenstone2/perllib/docprint.pm
===================================================================
--- /main/trunk/greenstone2/perllib/docprint.pm	(revision 32511)
+++ /main/trunk/greenstone2/perllib/docprint.pm	(revision 32512)
@@ -30,10 +30,33 @@
 package docprint;
 
+use constant OUTPUT_META_ONLY => 1;
+use constant OUTPUT_TEXT_ONLY => 2;
+use constant OUTPUT_ALL => 3;
+
 use strict;
 
 sub get_section_xml {
+    return &get_section_xml_from_root(@_);
+}
+
+sub get_section_xml_from_root {
+    my ($doc_obj, $options) = @_;
+    return &recursive_get_section_xml($doc_obj,$doc_obj->get_top_section(), $options);
+}
+
+sub recursive_get_section_xml {    
+    my ($doc_obj, $section, $options) = @_;
     
-    my ($doc_obj, $section) = @_;
-
+    # 'output' can be OUTPUT_ALL|OUTPUT_META_ONLY|OUTPUT_TEXT_ONLY
+    # If not provided, it defaults to OUTPUT_ALL.
+    # If OUTPUT_ALL, the metadata and full text both go into doc.xml
+    # If OUTPUT_META_ONLY, the metadata goes into doc.xml and full text goes elsewhere (mysql db).
+    # If OUTPUT_TEXT_ONLY, the full text goes into doc.xml and metadata goes elsewhere (mysql db).
+    # In the last two cases, an XML comment is left behind to indicate that the "missing" doc
+    # information is stored elsewhere.
+    if(!defined $options) {	
+	$options = {'output' => OUTPUT_ALL };
+    }
+    
     my $section_ptr = $doc_obj->_lookup_section ($section);
     return "" unless defined $section_ptr;
@@ -41,9 +64,13 @@
     my $all_text = "<Section>\n";
     $all_text .= "  <Description>\n";
-    
-    # output metadata
-    foreach my $data (@{$section_ptr->{'metadata'}}) {
-	my $escaped_value = &escape_text($data->[1]);
-	$all_text .= '    <Metadata name="' . $data->[0] . '">' . $escaped_value . "</Metadata>\n";
+
+    if($options->{'output'} == OUTPUT_ALL || $options->{'output'} == OUTPUT_META_ONLY) {
+	# output metadata
+	foreach my $data (@{$section_ptr->{'metadata'}}) {
+	    my $escaped_value = &escape_text($data->[1]);
+	    $all_text .= '    <Metadata name="' . $data->[0] . '">' . $escaped_value . "</Metadata>\n";
+	}
+    } else {
+	$all_text .= "<!-- metadata is stored elsewhere (MySQL database) -->\n";
     }
 
@@ -52,10 +79,14 @@
     # output the text
     $all_text .= "  <Content>";
-    $all_text .= &escape_text($section_ptr->{'text'});
+    if($options->{'output'} == OUTPUT_ALL || $options->{'output'} == OUTPUT_TEXT_ONLY) {
+	$all_text .= &escape_text($section_ptr->{'text'});
+    } else {
+	$all_text .= "<!-- full text is stored elsewhere (MySQL database) -->\n";
+    }
     $all_text .= "</Content>\n";
     
     # output all the subsections
     foreach my $subsection (@{$section_ptr->{'subsection_order'}}) {
-	$all_text .= &get_section_xml($doc_obj, "$section.$subsection");
+	$all_text .= &recursive_get_section_xml($doc_obj, "$section.$subsection");
     }
     
Index: /main/trunk/greenstone2/perllib/oaiinfo.pm
===================================================================
--- /main/trunk/greenstone2/perllib/oaiinfo.pm	(revision 32511)
+++ /main/trunk/greenstone2/perllib/oaiinfo.pm	(revision 32512)
@@ -162,6 +162,6 @@
 	# yet had done some import (and perhaps building) followed by a full re-import now.
 	# Since there was no activate and we're doing a removeold/full-rebuild now, can just
-	# work with a new tmpdb, even though one already existed, its contents can be wiped out.
-        # In such a scenario, we'll be deleting tmpdb. Then there  will be no livedb nor any tmpdb
+	# work with a new tmpdb: even though one already existed, its contents can be wiped out.
+        # In such a scenario, we'll be deleting tmpdb. Then there will be no livedb nor any tmpdb
 	# any more, so same situation as if importing the very first time when no oaidb exists either.
 
Index: /main/trunk/greenstone2/perllib/plugouts/GreenstoneXMLPlugout.pm
===================================================================
--- /main/trunk/greenstone2/perllib/plugouts/GreenstoneXMLPlugout.pm	(revision 32511)
+++ /main/trunk/greenstone2/perllib/plugouts/GreenstoneXMLPlugout.pm	(revision 32512)
@@ -76,5 +76,5 @@
 }
 
-sub saveas {
+sub old_unused_saveas {
     my $self = shift (@_);
     my ($doc_obj, $doc_dir) = @_;
@@ -117,5 +117,5 @@
     }
 
-    my $section_text = &docprint::get_section_xml($doc_obj,$doc_obj->get_top_section());
+    my $section_text = &docprint::get_section_xml($doc_obj);
     print $outhandler $section_text;
  
@@ -138,4 +138,87 @@
     $self->store_output_info_reference($doc_obj);
     
+}
+
+sub pre_saveas {
+    my $self = shift (@_);
+    my ($doc_obj, $doc_dir) = @_;
+    my $outhandler;
+    my $output_file;
+    if ($self->{'debug'}) {
+	$outhandler = STDOUT;
+    }
+    else {
+	   
+	$self->process_assoc_files($doc_obj, $doc_dir, '');
+	$self->process_metafiles_metadata ($doc_obj);
+	
+	# open up the outhandler    
+	if ($self->is_group() && !$self->{'new_doc_dir'}) { 
+	    # we already have a handle open ??
+	    $outhandler = $self->{'group_outhandler'};
+	} else {
+	    $output_file = &FileUtils::filenameConcatenate($self->{'output_dir'}, $doc_dir, "doc.xml");
+	    # open the new handle
+	    $self->open_xslt_pipe($output_file, $self->{'xslt_file'});
+
+	    if (defined $self->{'xslt_writer'}){
+		$outhandler = $self->{'xslt_writer'};
+	    }
+	    else{
+		$outhandler = $self->get_output_handler($output_file);
+	    }
+	    
+	    if ($self->is_group()) {
+		$self->{'group_outhandler'} = $outhandler;
+	    }
+	}
+    } # else not debug
+    binmode($outhandler,":utf8");
+
+    # only output the header if we have started a new doc
+    if (!$self->is_group() || $self->{'new_doc_dir'}) {
+	$self->output_xml_header($outhandler);
+    }
+ 
+    return ($outhandler, $output_file);
+}
+
+sub saveas {
+    my $self = shift (@_);
+    my ($doc_obj, $doc_dir) = @_;
+
+    # pre
+    my ($outhandler, $output_file) = $self->pre_saveas(@_);
+    push(@_, $outhandler, $output_file);
+
+    # write out the doc xml file for the current document
+    my $section_text = &docprint::get_section_xml($doc_obj);
+    print $outhandler $section_text;
+
+    # post
+    $self->post_saveas(@_);
+}
+
+sub post_saveas {
+    my $self = shift (@_);    
+    my ($doc_obj, $doc_dir, $outhandler, $output_file) = @_;
+    
+    # only output the footer if we are not doing group stuff. The group file will be finished in close_group_output
+    if (!$self->is_group()) {
+	$self->output_xml_footer($outhandler);
+    }
+
+    # close off the output - in a group process situation, this will be done by close_group_output
+    if (!$self->is_group() && !$self->{'debug'}) {
+	if (defined $self->{'xslt_writer'}){     
+	    $self->close_xslt_pipe(); 
+	}
+	else {
+	    &FileUtils::closeFileHandle($output_file, \$outhandler) if defined $output_file;
+	}
+    }
+    $self->{'short_doc_file'} = &FileUtils::filenameConcatenate($doc_dir, "doc.xml");  
+    
+    $self->store_output_info_reference($doc_obj);    
 }
 
