Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/09 11:01:12 (15 years ago)
Author:
epitzer
Message:

externalize tag names for XMl formatting/parsing. (#506)

Location:
branches/New Persistence Exploration/Persistence/Persistence
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/XmlFormatter.cs

    r1357 r1359  
    55
    66namespace 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 
    717  public class XmlFormatter {
    8 
     18   
    919    delegate string Formatter(ISerializationToken token);
    1020
     
    6070        attributes.Add("id", beginToken.Id.ToString());                                           
    6171      string result = Prefix +
    62                       FormatNode("COMPOSITE", attributes, NodeType.Start) + "\n";
     72                      FormatNode(XmlStrings.COMPOSITE, attributes, NodeType.Start) + "\n";
    6373      depth += 1;
    6474      return result;
     
    6777    private string FormatEnd(ISerializationToken token) {     
    6878      depth -= 1;
    69       return Prefix + "</COMPOSITE>\n";
     79      return Prefix + "</" + XmlStrings.COMPOSITE + ">\n";
    7080    }
    7181
     
    8090        attributes.Add("id", dataToken.Id.ToString());
    8191      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";     
    8494    }
    8595
     
    90100      if ( refToken.Name != null )
    91101        attributes.Add("name", refToken.Name);
    92       return Prefix + FormatNode("REFERENCE", attributes, NodeType.Inline) + "\n"; 
     102      return Prefix + FormatNode(XmlStrings.REFERENCE, attributes, NodeType.Inline) + "\n"; 
    93103    }
    94104
     
    98108      if (nullRefToken.Name != null)
    99109        attributes.Add("name", nullRefToken.Name);
    100       return Prefix + FormatNode("NULL", attributes, NodeType.Inline) + "\n";
     110      return Prefix + FormatNode(XmlStrings.NULL, attributes, NodeType.Inline) + "\n";
    101111    }
    102112
    103113    public IEnumerable<string> Format(Dictionary<string, int> typeCache) {
    104       yield return "<TYPECACHE>";
     114      yield return "<" + XmlStrings.TYPECACHE + ">";
    105115      foreach ( var pair in typeCache ) {
    106         yield return String.Format("  <TYPE id=\"{0}\" name=\"{1}\"/>",
     116        yield return String.Format("  <" + XmlStrings.TYPE + " id=\"{0}\" name=\"{1}\"/>",
    107117                                   pair.Value, pair.Key);       
    108118      }
    109       yield return "</TYPECACHE>";
     119      yield return "</" + XmlStrings.TYPECACHE + ">";
    110120    }
    111121  }
  • branches/New Persistence Exploration/Persistence/Persistence/XmlParser.cs

    r1357 r1359  
    2323      reader = XmlReader.Create(input, settings);
    2424      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}
    2929                   };
    3030    }
     
    8888      XmlReader xmlReader = XmlReader.Create(reader);
    8989      while ( xmlReader.Read() ) {
    90         if (xmlReader.Name == "TYPE") {         
     90        if (xmlReader.Name == XmlStrings.TYPE) {         
    9191          typeCache.Add(xmlReader.GetAttribute("name")
    9292          , int.Parse(xmlReader.GetAttribute("id")));
Note: See TracChangeset for help on using the changeset viewer.