我需要将 xml 根标签名称从“string”更改为“TramaOutput”。如何实现这一目标
public string ToXml()
{
XElement element = new XElement("TramaOutput",
new XElement("Artist", "bla"),
new XElement("Title", "Foo"));
return Convert.ToString(element);
}
为此,输出为:
<string>
<TramaOutput>
<Artist>bla</Artist>
<Title>Foo</Title>
</TramaOutput>
</string>
在下面提到的代码中,我收到一个错误,例如“不能在架构的顶层使用通配符”。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Xml.Linq;
namespace WebApplication1
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public XElement getXl()
{
XElement element = new XElement("Root",new XElement("BookId",1),new XElement("BookId",2));
return element;
}
}
}