1

我需要从我的 MVC api 响应中删除 xsd 和 xsi 命名空间,但我无法使其工作。(我需要删除它们的原因是因为我们将其发送给第三方地图提供商,如果包含它们,它就不起作用。)我已经阅读了很多其他问题,例如这个问题完全相同的事情,但答案不起作用,我尝试按照这个答案实现自定义格式化程序,但不幸的是也没有运气。有谁知道我需要做什么?我应该放弃并改用处理程序吗?

模型:

[XmlType(TypeName = "MapPoints")]
[XmlRoot(DataType = "", Namespace = "http://tempuri.org/XMLFile1.xsd")]
public class MapPointList
{
    public MapPointList()
    {
        Points = new List<MapPoint>();
    }

    [XmlElement("Point")]
    public List<MapPoint> Points { get; set; }
}

控制器:

    public class MyController : ApiController
{
    public MyController()
    {
        var xmlFormatter = GlobalConfiguration.Configuration.Formatters.XmlFormatter;
        xmlFormatter.SetSerializer<MapPointList>(new XmlSerializer(typeof (MapPointList)));
        xmlFormatter.SetSerializer<MapPoint>(new XmlSerializer(typeof (MapPoint)));
    }

    [HttpGet]
    public MapPointList SearchMap()
    {
        var items = new MapPointList();
        // get the items

        return items;
    }
}

我的根应该是这样的:

<MapPoints xmlns="http://tempuri.org/XMLFile1.xsd">

让我知道是否需要添加更多信息。

4

0 回答 0