Index: trunk/gsdl/perllib/plugins/MARCXMLPlug.pm
===================================================================
--- trunk/gsdl/perllib/plugins/MARCXMLPlug.pm	(revision 13486)
+++ trunk/gsdl/perllib/plugins/MARCXMLPlug.pm	(revision 13496)
@@ -71,5 +71,6 @@
     $self->{'metadata_mapping'} = undef;
     $self->{'num_processed'} = 0;
-    
+    $self->{'indent'} = 0;
+
     return bless $self, $class;
 }
@@ -168,5 +169,5 @@
     my $file = $self->{'file'};
     my $filename = $self->{'filename'};
-    
+       
     my ($language, $encoding) = $self->textcat_get_language_encoding ($filename);
 
@@ -174,5 +175,5 @@
     $self->{'encoding'} = $encoding;
     $self->{'element_count'} = 1;
-    
+    $self->{'indent'} = 0;
     my $outhandle = $self->{'outhandle'};
     print $outhandle "MARCXMLPlug: processing $self->{'file'}\n" if $self->{'verbosity'} > 1;
@@ -189,10 +190,8 @@
     my $expat = shift;
     my $element = shift;  
+
+    my $text =  $self->escape_text($_); 
   
     $self->{'current_element'} = $element;
-
-    if ($element ne "collection"){
-	$self->{'content'} .= $_;
-    }
 
     ##get all atributes of this element and store it in a map name=>value    
@@ -201,5 +200,5 @@
     while ($attrstring =~ /(\w+)=\"(\w+)\"/){
 	$attr_map{$1}=$2;
-	$attrstring = $';
+	$attrstring = $'; #'
     }
 
@@ -209,5 +208,5 @@
     ##create a new document for each record 
     if ($element eq "record") {
-	my $filename = $self->{'filename'};
+        my $filename = $self->{'filename'};
 	my $language = $self->{'language'};
         my $encoding = $self->{'encoding'};
@@ -240,5 +239,5 @@
     ## get the marc code, for example 520
      if ($element eq "datafield") {
-	 if (defined $attr_map{'tag'} and $attr_map{'tag'} ne ""){
+    	 if (defined $attr_map{'tag'} and $attr_map{'tag'} ne ""){
 	     $self->{'current_tag'} = $attr_map{tag};  
 	 }
@@ -248,8 +247,25 @@
     ## append the subcode to the marc code for example 520a or 520b 
     if ($element eq "subfield"){
-	if (defined $attr_map{'code'} and $attr_map{'code'} ne "" and $self->{'current_tag'} ne ""){
+   	if (defined $attr_map{'code'} and $attr_map{'code'} ne "" and $self->{'current_tag'} ne ""){
 	    $self->{'current_code'} = $attr_map{'code'};
 	}
     }
+
+   if ($element eq "record"){
+        $self->{'indent'} = 0;
+    }
+    else {
+         if ($element ne "subfield"){
+              $self->{'indent'} = 1;
+         }
+         else{
+           $self->{'indent'} = 2;
+         }
+    }
+    
+    
+   if ($element ne "collection"){
+        $self->{'content'} .= "<br/>".$self->calculate_indent($self->{'indent'}).$text;
+   }
 }
 
@@ -259,12 +275,13 @@
     my $self = shift(@_);
     my ($expat, $element) = @_;
-
-    $self->{'content'} .= $_;
-
+    my $text =  $self->escape_text($_); 
+ 
     if ($element eq "record" and defined $self->{'doc_obj'}) {
 	# process the document
 	my $processor = $self->{'processor'};
 	my $doc_obj = $self->{'doc_obj'};
-	$doc_obj->add_utf8_text($doc_obj->get_top_section(), $self->{'content'});
+        $self->{'content'} .= "<br/>".$text;
+      
+	$doc_obj->add_utf8_text($doc_obj->get_top_section(),$self->{'content'});
         $processor->process($doc_obj);
 
@@ -272,4 +289,5 @@
 	$self->{'content'} = "";  
 	$self->{'doc_obj'} = undef;
+        return;
     }
 
@@ -322,4 +340,13 @@
 	$self->{'current_tag'} = "";
     }
+  
+   if ($element eq "datafield"){
+       $self->{'indent'} = 1;
+       $self->{'content'} .= "<br/>".$self->calculate_indent($self->{'indent'}).$text;
+   }
+    else{
+	$self->{'content'} .= $text;   
+    }
+     
 }
 
@@ -345,8 +372,32 @@
     }
     
-    $self->{'content'} .= $_;
+    $self->{'content'} .=$self->escape_text($_);
    
 }
 
+sub calculate_indent{
+   my ($self,$num) = @_;
+
+   my $indent ="";
+  
+   for (my $i=0; $i<$num;$i++){
+       $indent .= "&nbsp;&nbsp;&nbsp;&nbsp;";
+    } 
+ 
+   return $indent;
+
+}
+
+sub escape_text {
+    my ($self,$text) = @_;
+    # special characters in the xml encoding
+    $text =~ s/&/&amp;/g; # this has to be first...
+    $text =~ s/</&lt;/g;
+    $text =~ s/>/&gt;/g;
+    $text =~ s/\"/&quot;/g;
+
+    return $text;
+}
+
 
 1;
