Skip to main content

Blog de Alejandro Avila

Go Search
Home
  

Blog de Alejandro Avila > Posts > Serialize, deserialize XML with arraylist
Serialize, deserialize XML with arraylist

public class SearchBoxConfiguration

{

[XmlElement("Field", Type = typeof(Field))]

public ArrayList Fields;

[XmlIgnore]

public int FieldCount

{

get

{

return Fields.Count;

}

}

public SearchBoxConfiguration()

{

Fields = new ArrayList();

}

public static string Serialize(SearchBoxConfiguration configuration)

{

string xml = string.Empty;

XmlSerializer serializer = new XmlSerializer(typeof(SearchBoxConfiguration), new Type[] { typeof(Field) });

XmlSerializerNamespaces xsn = new XmlSerializerNamespaces();

xsn.Add("", "");

using (StringWriter sw = new StringWriter(new StringBuilder()))

{

serializer.Serialize(sw, configuration, xsn);

xml = sw.ToString();

}

return xml;

}

public static SearchBoxConfiguration Deserialize(string xmlConfiguration)

{

XmlSerializer serializer = new XmlSerializer(typeof(SearchBoxConfiguration), new Type[] { typeof(Field) });

SearchBoxConfiguration ps;

using (StringReader sr = new StringReader(xmlConfiguration))

{

ps = serializer.Deserialize(sr) as SearchBoxConfiguration;

}

return ps;

}

}

Comments

There are no comments yet for this post.