日期:2014-05-18  浏览次数:20453 次

asp.net 搞ajax 有人这样做吗?
C# 服务端要返回 xml 格式的数据到浏览器。 
  难道大家用xmlDocument 来创建数据?

哎,小弟不会XMLDocument 来创建啊,直接拼就算了!

C# code
StringBuilder xmlDoc = new StringBuilder();
xmlDoc.Append("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
xmlDoc.Append("<table id = 'returnMainXmlTable' >");
foreach (string key in dtable.Keys)
{
    Dictionary<string, object> dictNote = (Dictionary<string, object>)dtable[key];
    xmlDoc.Append("<tr>");
    xmlDoc.Append("<td name='id'>" + dictNote["id"].ToString() + "</td>");
    xmlDoc.Append("<td name='pageName'>" + dictNote["pageName"].ToString() + "</td>");
    xmlDoc.Append("<td name='content'>" + dictNote["text"].ToString() + "</td>");
    xmlDoc.Append("</tr>"); 
}
xmlDoc.Append("</table>");
context.Response.Write(xmlDoc.ToString());

 
结果:也行啊,

 以前都用josn来搞的,但josn 太小气了,一定量(有结构的)的数据就搞不定!

大家有我这么干的吗?

------解决方案--------------------
建议稍微学一下XmlDocument,增删查改,不难的,可读性可能好点。直接拼当然也可以,因为xml实质就是个字符串。
------解决方案--------------------
嗯 直接拼是可以的