Changeset 1359
- Timestamp:
- 03/19/09 11:01:12 (16 years ago)
- Location:
- branches/New Persistence Exploration/Persistence/Persistence
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs
r1357 r1359 5 5 6 6 namespace HeuristicLab.Persistence { 7 8 struct XmlStrings { 9 public const string PRIMITIVE = "PRIMITVE"; 10 public const string COMPOSITE = "COMPOSITE"; 11 public const string REFERENCE = "REFERENCE"; 12 public const string NULL = "NULL"; 13 public const string TYPECACHE = "TYPCACHE"; 14 public const string TYPE = "TYPE"; 15 } 16 7 17 public class XmlFormatter { 8 18 9 19 delegate string Formatter(ISerializationToken token); 10 20 … … 60 70 attributes.Add("id", beginToken.Id.ToString()); 61 71 string result = Prefix + 62 FormatNode( "COMPOSITE", attributes, NodeType.Start) + "\n";72 FormatNode(XmlStrings.COMPOSITE, attributes, NodeType.Start) + "\n"; 63 73 depth += 1; 64 74 return result; … … 67 77 private string FormatEnd(ISerializationToken token) { 68 78 depth -= 1; 69 return Prefix + "</ COMPOSITE>\n";79 return Prefix + "</" + XmlStrings.COMPOSITE + ">\n"; 70 80 } 71 81 … … 80 90 attributes.Add("id", dataToken.Id.ToString()); 81 91 return Prefix + 82 FormatNode( "PRIMITIVE", attributes, NodeType.Start) +83 dataToken.SerialData + "</ PRIMITIVE>\n";92 FormatNode(XmlStrings.PRIMITIVE, attributes, NodeType.Start) + 93 dataToken.SerialData + "</" + XmlStrings.PRIMITIVE + ">\n"; 84 94 } 85 95 … … 90 100 if ( refToken.Name != null ) 91 101 attributes.Add("name", refToken.Name); 92 return Prefix + FormatNode( "REFERENCE", attributes, NodeType.Inline) + "\n";102 return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\n"; 93 103 } 94 104 … … 98 108 if (nullRefToken.Name != null) 99 109 attributes.Add("name", nullRefToken.Name); 100 return Prefix + FormatNode( "NULL", attributes, NodeType.Inline) + "\n";110 return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\n"; 101 111 } 102 112 103 113 public IEnumerable<string> Format(Dictionary<string, int> typeCache) { 104 yield return "< TYPECACHE>";114 yield return "<" + XmlStrings.TYPECACHE + ">"; 105 115 foreach ( var pair in typeCache ) { 106 yield return String.Format(" < TYPEid=\"{0}\" name=\"{1}\"/>",116 yield return String.Format(" <" + XmlStrings.TYPE + " id=\"{0}\" name=\"{1}\"/>", 107 117 pair.Value, pair.Key); 108 118 } 109 yield return "</ TYPECACHE>";119 yield return "</" + XmlStrings.TYPECACHE + ">"; 110 120 } 111 121 } -
branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs
r1357 r1359 23 23 reader = XmlReader.Create(input, settings); 24 24 handlers = new Dictionary<string, Handler> { 25 { "PRIMITIVE", ParsePrimitive},26 { "COMPOSITE", ParseComposite},27 { "REFERENCE", ParseReference},28 { "NULL", ParseNull}25 {XmlStrings.PRIMITIVE, ParsePrimitive}, 26 {XmlStrings.COMPOSITE, ParseComposite}, 27 {XmlStrings.REFERENCE, ParseReference}, 28 {XmlStrings.NULL, ParseNull} 29 29 }; 30 30 } … … 88 88 XmlReader xmlReader = XmlReader.Create(reader); 89 89 while ( xmlReader.Read() ) { 90 if (xmlReader.Name == "TYPE") {90 if (xmlReader.Name == XmlStrings.TYPE) { 91 91 typeCache.Add(xmlReader.GetAttribute("name") 92 92 , int.Parse(xmlReader.GetAttribute("id")));
Note: See TracChangeset
for help on using the changeset viewer.