- Timestamp:
- 04/16/09 12:58:14 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/XmlGenerator.cs
r1564 r1566 21 21 public const string METAINFO = "METAINFO"; 22 22 } 23 23 24 24 public class XmlGenerator : GeneratorBase<string> { 25 25 26 26 private int depth; 27 27 … … 45 45 if (type == NodeType.End) 46 46 sb.Append('/'); 47 sb.Append(name); 47 sb.Append(name); 48 48 foreach (var attribute in attributes) { 49 49 if (attribute.Value != null && !string.IsNullOrEmpty(attribute.Value.ToString())) { … … 58 58 sb.Append('/'); 59 59 sb.Append(">"); 60 return sb.ToString(); 60 return sb.ToString(); 61 61 } 62 62 … … 65 65 } 66 66 67 protected override string Format(BeginToken beginToken) { 67 protected override string Format(BeginToken beginToken) { 68 68 var attributes = new Dictionary<string, object> { 69 69 {"name", beginToken.Name}, … … 76 76 } 77 77 78 protected override string Format(EndToken endToken) { 78 protected override string Format(EndToken endToken) { 79 79 depth -= 1; 80 80 return Prefix + "</" + XmlStrings.COMPOSITE + ">\r\n"; 81 81 } 82 82 83 protected override string Format(PrimitiveToken dataToken) { 83 protected override string Format(PrimitiveToken dataToken) { 84 84 var attributes = 85 85 new Dictionary<string, object> { … … 89 89 return Prefix + 90 90 FormatNode(XmlStrings.PRIMITIVE, attributes, NodeType.Start) + 91 ((XmlString)dataToken.SerialData).Data + "</" + XmlStrings.PRIMITIVE + ">\r\n"; 91 ((XmlString)dataToken.SerialData).Data + "</" + XmlStrings.PRIMITIVE + ">\r\n"; 92 92 } 93 93 94 protected override string Format(ReferenceToken refToken) { 94 protected override string Format(ReferenceToken refToken) { 95 95 var attributes = new Dictionary<string, object> { 96 96 {"ref", refToken.Id}, 97 {"name", refToken.Name}}; 98 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 97 {"name", refToken.Name}}; 98 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\r\n"; 99 99 } 100 100 101 protected override string Format(NullReferenceToken nullRefToken) { 101 protected override string Format(NullReferenceToken nullRefToken) { 102 102 var attributes = new Dictionary<string, object>{ 103 {"name", nullRefToken.Name}}; 103 {"name", nullRefToken.Name}}; 104 104 return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\r\n"; 105 105 } … … 127 127 } 128 128 129 public static void Serialize(object o, string filename) { 129 public static void Serialize(object o, string filename) { 130 130 Serialize(o, filename, ConfigurationService.Instance.GetDefaultConfig(new XmlFormat())); 131 131 } … … 135 135 XmlGenerator generator = new XmlGenerator(); 136 136 ZipOutputStream zipStream = new ZipOutputStream(File.Create(filename)); 137 zipStream.SetLevel(9); 138 zipStream.PutNextEntry(new ZipEntry("data.xml")); 137 zipStream.SetLevel(9); 138 zipStream.PutNextEntry(new ZipEntry("data.xml")); 139 139 StreamWriter writer = new StreamWriter(zipStream); 140 ILog logger = Logger.GetDefaultLogger(); 140 ILog logger = Logger.GetDefaultLogger(); 141 141 foreach (ISerializationToken token in serializer) { 142 142 string line = generator.Format(token); … … 151 151 logger.Debug(line); 152 152 } 153 writer.Flush(); 154 zipStream.Close(); 153 writer.Flush(); 154 zipStream.Close(); 155 155 } 156 156
Note: See TracChangeset
for help on using the changeset viewer.