Index: main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java	(revision 33737)
+++ main/trunk/gli/src/org/greenstone/gatherer/metadata/FilenameEncoding.java	(revision 33738)
@@ -376,5 +376,5 @@
 	
 	// follows Dr Bainbridge's method below, but with a String parameter instead of a file parameter
-	public static String filenameToURLEncoding(String filename) {
+	public static String UNUSED_filenameToURLEncoding(String filename) {
 		if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) {
 		    return filename;
@@ -424,5 +424,5 @@
 	
 	// follows Dr Bainbridge's method below, but with a String parameter instead of a file parameter	
-	public static String _filenameToURLEncoding(String filename) {
+	public static String filenameToURLEncoding(String filename) {
 		if(!MULTIPLE_FILENAME_ENCODINGS_SUPPORTED) { // on a UTF-8 file system, DO NOT do the stuff below, just return input param
 		    return filename;
Index: main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java	(revision 33737)
+++ main/trunk/gli/src/org/greenstone/gatherer/metadata/MetadataXMLFile.java	(revision 33738)
@@ -287,5 +287,5 @@
 		// so need to make sure everything hex has been decoded (no more hex) to compare apples with apples		
 		if (hexdecoded_regexed_file_relative_path.matches(hexdecoded_current_filename_element_value)) {	//if (file_relative_path.matches(current_filename_element_value)) {
-			//System.err.println("   @@@ Found a match in meta.xml for hexdecoded_regexed_file_relative_path: " + hexdecoded_regexed_file_relative_path);
+			//System.err.println("   @@@ Found a match in meta.xml for hexdecoded_regexed_file_relative_path: " + hexdecoded_regexed_file_relative_path + "\n");
 		    current_fileset_matches = true;
 		    if (!file_relative_path.equals("") && current_filename_element_value.equals(DIRECTORY_FILENAME)) {
@@ -668,4 +668,8 @@
 		}
 		
+		String metadata_xml_file_directory_path = FilenameEncoding.filenameToURLEncoding(".");
+		metadata_xml_file_directory_path = metadata_xml_file_directory_path.substring(0, metadata_xml_file_directory_path.length()-2); // cut off /. at end
+		System.err.println("@@@ metadata_xml_file_directory_path: " + metadata_xml_file_directory_path);
+		
 		//System.err.println("PARSED loaded_file contains:\n" +  XMLTools.elementToString(doc.getDocumentElement(), true));
 		
@@ -681,12 +685,23 @@
 				String filename = XMLTools.getElementTextValue(filename_element);
 				if(!filename.equals(DIRECTORY_FILENAME)) {
-					//System.err.println("Filename before reencoding was: " + filename);
-					// reencode filename					
-					// can't convert to URI with backslash-escaped chars (backslash used in regexed filename are illegal in URI object
-					// created by filenameToURLEncoding).
+					// Reencode filename after parseXML() had the side-effect of decoding entities in filename elements
+					
+					//System.err.println("Filename before reencoding was: " + filename);					
+					
+					// Can't convert to URI with backslash-escaped chars (backslash used in regexed filename are illegal in URI object
+					// created by filenameToURLEncoding). So replace backslashes in regex with url-encoded hex-value of backslash, %5C.
 					String encoded_filename = filename.replace("\\", "%5C"); 
 					encoded_filename = FilenameEncoding.filenameToURLEncoding(encoded_filename);
-					// escape chars for regex again
-					encoded_filename = encoded_filename.replace("%5C", "\\");
+
+					// now lop off the metadataxml dir prefix the FilenameEncoding.filenameToURLEncoding(STRING) variant would have added
+					encoded_filename = encoded_filename.substring(metadata_xml_file_directory_path.length());
+					if (encoded_filename.startsWith(FilenameEncoding.URL_FILE_SEPARATOR)) {
+						encoded_filename = encoded_filename.substring(FilenameEncoding.URL_FILE_SEPARATOR.length());
+					}
+	
+					// Reintrodudce the backslash characters in place of their %5C hex placeholders
+					encoded_filename = encoded_filename.replace("%5C", "\\");				
+					
+					// Update filename element in DOM
 					XMLTools.setElementTextValue(filename_element, encoded_filename);
 					//System.err.println("Filename after reencoding was: " + encoded_filename);
