IDictionary To Xml String - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IDictionary

Description

IDictionary To Xml String

Demo Code


using System.Text;
using System.Linq;
using System.IO;//from   w  w w  .  j  ava 2 s.c o m
using System.Collections.Generic;
using System;

public class Main{

        public static string ToXmlString(this IDictionary<object, object> dictionary)
        {
            var sb = new StringBuilder();
            sb.Append("<xml>");
            foreach (var key in dictionary.Keys)
            {
                var value = dictionary[key];
                if (value != null)
                {
                    sb.AppendFormat("<{0}>{1}</{0}>", key, value);
                }
            }
            sb.Append("</xml>");
            return sb.ToString();
        }
}

Related Tutorials