Monday, November 10, 2008

Handling Special Case Like & and > while Genrating Xml

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;
namespace Utility
{
class GenrateXML
{
public static string Genrate(string Screen, NameValueCollection nvCollection)
{
StringBuilder strXML=new StringBuilder();
strXML.Append("");

strXML.Append("<");
strXML.Append(Screen);
strXML.Append(">");

for (int i = 0; i < nvCollection.Count; i++)
{
strXML.Append("<");
strXML.Append(nvCollection.GetKey(i));
strXML.Append(">");

string strValue = nvCollection.Get(i).Replace("&", "&");
strValue = strValue.Replace("<", "<");
strValue = strValue.Replace(">", ">");

strXML.Append(strValue);

strXML.Append(" strXML.Append(nvCollection.GetKey(i));
strXML.Append(">");
}
strXML.Append(" strXML.Append(Screen);
strXML.Append(">");
strXML.Append("
");
//strXML.Replace("&", "&");
return strXML.ToString();
}
}
}

No comments: