Rdz.XML.CommonXmlSerializer

Introductionary
This function to help to use serializer and deserializer much more easier than ever. Just need to inherit CommonXmlSerializer and class can be used as Xml object without much hassles to create Deserialize and Serialize function.

How to Use
You only need to create 2 files. First one is the base class for your Xml (required), and second is the Xml file itself (optional).

	[XmlRoot("Config")]
	public class Config : CommonXmlSerializer
	{
		public string QueryText { get; set; }
		public string ViewFields { get; set; }
		public string Lists { get; set; }
		public string Webs { get; set; }
		public string SiteUrl { get; set; }
	}

<?xml version="1.0" encoding="utf-8" ?>
<Config>
	<QueryText>
		<![CDATA[<Where><Or><Contains><FieldRef Name="Title" /><Value Type="Text">{0}</Value></Contains><Contains><FieldRef Name="FileRef" /><Value Type="Text">{0}</Value></Contains></Or></Where>]]>
	</QueryText>
	<ViewFields>
		<![CDATA[<FieldRef Name="Title" /><FieldRef Name="FileRef" Nullable="TRUE" />]]>
	</ViewFields>
	<Lists>
		<![CDATA[<Lists ServerTemplate="851" />]]>
	</Lists>
	<Webs>
		<![CDATA[<Webs Scope="Recursive" />]]>
	</Webs>
	<SiteUrl>http://mana/sites/intranet/Wiki/</SiteUrl>
</Config>

And below is the code for another call to get the Xml values.

        public static Config GetXmlValue()
        {
            try
            {
                var C = new Config();
                C = (Config)C.Deserialize(File.ReadAllText(@"Config.xml"));

                //Below are the codes to utilize the deserialized Xml
                var x = C.QueryText;
                return C;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

And below is the code for another call to save the Xml values from object.

        public static string SaveXmlValue()
        {
            try
            {
                var C = new Config();
                C.QueryText = "Aduuuh maaaang, pusingnya.......";
                return C.Serialize();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Last edited Mar 8, 2013 at 10:41 AM by radityoardi, version 6

Comments

No comments yet.