在webservice里面,在浏览器中的格式不是xml的格式,试了很多方法都不行,
请大侠帮小弟解答,急啊!!!
[WebMethod]
public string DemonstrateGetXml()
{
DataSet dataSet = new DataSet("dataSet");
DataTable table = dataSet.Tables.Add("Items");
//table.Columns.Add("ItemId", typeof(int));
//table.Columns.Add("ItemName", typeof(string));
//table.Columns.Add("ItemValue",typeof(string));
//table.Columns.Add("ItemStatus", typeof(string));
table.Columns.Add("id", typeof(string));
table.Columns.Add("Item", typeof(string)); // Add ten rows.
DataRow row;
for (int i = 0; i < 10; i++)
{
row = table.NewRow();
row["id"] = i;
row["Item"] = "Item" + i;
table.Rows.Add(row);
}
string str = dataSet.GetXml();
return str;
}
}
结果是这样的
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://tempuri.org/"><dataSet> <Items> <id>0</id> <Item>Item0</Item> </Items> <Items> <id>1</id> <Item>Item1</Item> </Items> <Items> <id>2</id> <Item>Item2</Item> </Items> <Items> <id>3</id> <Item>Item3</Item> </Items> <Items> <id>4</id> <Item>Item4</Item> </Items> <Items> <id>5</id> <Item>Item5</Item> </Items> <Items> <id>6</id> <Item>Item6</Item> </Items> <Items> <id>7</id> <Item>Item7</Item> </Items> <Items> <id>8</id> <Item>Item8</Item> </Items> <Items> <id>9</id> <Item>Item9</Item> </Items> </dataSet></string>
string xml = @"<?xml version='1.0' encoding='utf-8' ?><string xmlns='http://tempuri.org/'><dataSet> <Items> <id>0</id> <Item>Item0</Item> </Items> <Items> <id>1</id> <Item>Item1</Item> </Items> <Items> <id>2</id> <Item>Item2</Item> </Items> <Items> <id>3</id> <Item>Item3</Item> </Items> <Items> <id>4</id> <Item>Item4</Item> </Items> <Items> <id>5</id> <Item>Item5</Item> </Items> <Items> <id>6</id> <Item>Item6</Item> </Items> <Items> <id>7</id> <Item>Item7</Item> </Items> <Items> <id>8</id> <Item>Item8</Item> </Items> <Items> <id>9</id> <Item>Item9</Item> </Items> </dataSet></string>"; System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "Text/XML";
System.Web.HttpContext.Current.Response.Expires = 0; System.Web.HttpContext.Current.Response.Cache.SetNoStore();
System.Web.HttpContext.Current.Response.Write(xml.ToString());
System.Web.HttpContext.Current.Response.End();
在网页上显示的就是我贴上去的那个xml字符串,
就是return的内容,我是想return在网页上的是
格式化的xml,而现在是xml字符串,没有缩进换行
在网页上显示的就是我贴上去的那个xml字符串,
就是return的内容,我是想return在网页上的是
格式化的xml,而现在是xml字符串,没有缩进换行
是的额,请你把我的代码复制到你得到的那个xml字符串的下面,跟你的代码上下文配合一下,运行看看效果吧。
在网页上显示的就是我贴上去的那个xml字符串,
就是return的内容,我是想return在网页上的是
格式化的xml,而现在是xml字符串,没有缩进换行
是的额,请你把我的代码复制到你得到的那个xml字符串的下面,跟你的代码上下文配合一下,运行看看效果吧。
哇撒 太神奇了 我好好研究一下
真心非常感谢你的耐心大姐 你是好人 好人有好报