创建XML字符串
public string show(string yourname)
{
//return "http://aaaaa"+"欢迎"+yourname;
//生成xml字符串:
using (StringWriter sw = new StringWriter())
{
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
xtw.WriteStartDocument();
xtw.WriteStartElement("root");
//test
xtw.WriteStartElement("test");
xtw.WriteString("test content");
xtw.WriteEndElement();
//test2
xtw.WriteStartElement("test2");
//testSub
xtw.WriteStartElement("testSub");
xtw.WriteString("Sub content");
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();//root
xtw.WriteEndDocument();
string result = sw.ToString();
return result.Replace("utf-8", "gb2312").Replace("utf-16", "gb2312");
}
}
{
//return "http://aaaaa"+"欢迎"+yourname;
//生成xml字符串:
using (StringWriter sw = new StringWriter())
{
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
xtw.WriteStartDocument();
xtw.WriteStartElement("root");
//test
xtw.WriteStartElement("test");
xtw.WriteString("test content");
xtw.WriteEndElement();
//test2
xtw.WriteStartElement("test2");
//testSub
xtw.WriteStartElement("testSub");
xtw.WriteString("Sub content");
xtw.WriteEndElement();
xtw.WriteEndElement();
xtw.WriteEndElement();//root
xtw.WriteEndDocument();
string result = sw.ToString();
return result.Replace("utf-8", "gb2312").Replace("utf-16", "gb2312");
}
}