这是我希望 Web 服务提供的 XML:
<business>
<locations>
<location>location 1</location>
<location>location 2</location>
</locations>
</business>
但是,将返回以下内容:
<business>
<locations>
<location>
<name>location 1</name>
</location>
<location>
<name>location 2</name>
</location>
</locations>
</business>
这是使用的代码:
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public Business GetBusiness()
{
var business = new Business();
business.Locations = new List<Location>();
business.Locations.Add(new Location { Name = "location 1" });
business.Locations.Add(new Location { Name = "location 2" });
return business;
}
[XmlType(TypeName = "business")]
public class Business
{
[XmlArray(ElementName = "locations")]
[XmlArrayItem(ElementName = "location")]
public List<Location> Locations { get; set; }
}
[XmlType(TypeName = "location")]
public class Location
{
[XmlElement(ElementName = "name")]
public string Name { get; set; }
}
如何获得包含位置标签而不是名称标签的位置字符串?
TIA,乔治