diff orange/serialization/archives/XMLArchive.d @ 46:d6fbd0b3586e

Issue 8: Wrong results for array of arrays. (Temporary fix).
author Jacob Carlborg <doob@me.com>
date Tue, 09 Aug 2011 11:38:50 +0200
parents 3cd22957e411
children 9c9bbef6bf5e
line wrap: on
line diff
--- a/orange/serialization/archives/XMLArchive.d	Tue Aug 09 10:13:29 2011 +0200
+++ b/orange/serialization/archives/XMLArchive.d	Tue Aug 09 11:38:50 2011 +0200
@@ -773,7 +773,7 @@
 			auto length = fromData!(size_t)(getValueOfAttribute(Attributes.lengthAttribute, element));
 			auto offset = fromData!(size_t)(getValueOfAttribute(Attributes.offsetAttribute, element));
 			auto id = toId(element.value);
-			
+
 			return Slice(length, offset, id);
 		}
 		
@@ -1051,7 +1051,7 @@
 	}
 	
 	private doc.Node getElement (Data tag, string key, Data attribute = Attributes.keyAttribute, bool throwOnError = true)
-	{		
+	{
 		auto set = lastElement.query[tag].attribute((doc.Node node) {
 			if (node.name == attribute && node.value == key)
 				return true;
@@ -1059,22 +1059,29 @@
 			return false;
 		});
 
-		if (set.nodes.length == 1)
-			return set.nodes[0].parent;
+		version (Tango)
+		{
+			if (set.nodes.length == 1)
+				return set.nodes[0].parent;
+		}
 		
 		else
+		{	// Temporary fix, this is probably a problem in the Phobos
+			// implementation of the XML query function
+			if (set.nodes.length > 0)
+				return set.nodes[set.nodes.length - 1].parent;
+		}
+
+		if (throwOnError && errorCallback)
 		{
-			if (throwOnError && errorCallback)
-			{
-				if (set.nodes.length == 0)					
-					errorCallback(new ArchiveException(`Could not find an element "` ~ to!(string)(tag) ~ `" with the attribute "` ~ to!(string)(Attributes.keyAttribute) ~ `" with the value "` ~ to!(string)(key) ~ `".`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]);
-				
-				else
-					errorCallback(new ArchiveException(`Could not unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]);
-			}
+			if (set.nodes.length == 0)
+				errorCallback(new ArchiveException(`Could not find an element "` ~ to!(string)(tag) ~ `" with the attribute "` ~ to!(string)(Attributes.keyAttribute) ~ `" with the value "` ~ to!(string)(key) ~ `".`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]);
 
-			return doc.Node.invalid;
+			else
+				errorCallback(new ArchiveException(`Could not unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]);
 		}
+
+		return doc.Node.invalid;
 	}
 	
 	private Data getValueOfAttribute (Data attribute, doc.Node element = doc.Node.invalid)