comparison 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
comparison
equal deleted inserted replaced
45:3cd22957e411 46:d6fbd0b3586e
771 if (element.isValid) 771 if (element.isValid)
772 { 772 {
773 auto length = fromData!(size_t)(getValueOfAttribute(Attributes.lengthAttribute, element)); 773 auto length = fromData!(size_t)(getValueOfAttribute(Attributes.lengthAttribute, element));
774 auto offset = fromData!(size_t)(getValueOfAttribute(Attributes.offsetAttribute, element)); 774 auto offset = fromData!(size_t)(getValueOfAttribute(Attributes.offsetAttribute, element));
775 auto id = toId(element.value); 775 auto id = toId(element.value);
776 776
777 return Slice(length, offset, id); 777 return Slice(length, offset, id);
778 } 778 }
779 779
780 return Slice.init; 780 return Slice.init;
781 } 781 }
1049 1049
1050 return null; 1050 return null;
1051 } 1051 }
1052 1052
1053 private doc.Node getElement (Data tag, string key, Data attribute = Attributes.keyAttribute, bool throwOnError = true) 1053 private doc.Node getElement (Data tag, string key, Data attribute = Attributes.keyAttribute, bool throwOnError = true)
1054 { 1054 {
1055 auto set = lastElement.query[tag].attribute((doc.Node node) { 1055 auto set = lastElement.query[tag].attribute((doc.Node node) {
1056 if (node.name == attribute && node.value == key) 1056 if (node.name == attribute && node.value == key)
1057 return true; 1057 return true;
1058 1058
1059 return false; 1059 return false;
1060 }); 1060 });
1061 1061
1062 if (set.nodes.length == 1) 1062 version (Tango)
1063 return set.nodes[0].parent; 1063 {
1064 if (set.nodes.length == 1)
1065 return set.nodes[0].parent;
1066 }
1064 1067
1065 else 1068 else
1069 { // Temporary fix, this is probably a problem in the Phobos
1070 // implementation of the XML query function
1071 if (set.nodes.length > 0)
1072 return set.nodes[set.nodes.length - 1].parent;
1073 }
1074
1075 if (throwOnError && errorCallback)
1066 { 1076 {
1067 if (throwOnError && errorCallback) 1077 if (set.nodes.length == 0)
1068 { 1078 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]);
1069 if (set.nodes.length == 0) 1079
1070 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]); 1080 else
1071 1081 errorCallback(new ArchiveException(`Could not unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]);
1072 else
1073 errorCallback(new ArchiveException(`Could not unarchive the value with the key "` ~ to!(string)(key) ~ `" due to malformed data.`, __FILE__, __LINE__), [tag, Attributes.keyAttribute, key]);
1074 }
1075
1076 return doc.Node.invalid;
1077 } 1082 }
1083
1084 return doc.Node.invalid;
1078 } 1085 }
1079 1086
1080 private Data getValueOfAttribute (Data attribute, doc.Node element = doc.Node.invalid) 1087 private Data getValueOfAttribute (Data attribute, doc.Node element = doc.Node.invalid)
1081 { 1088 {
1082 if (!element.isValid) 1089 if (!element.isValid)