从 xml 导出的文件中删除 xmlns:xsi 和 xmlns:xsd 命名空间

问题描述

我认为当用户导出到 SAP 模块时,这个命名空间会出现问题,我该如何删除它。如果只保留 XMLTYPE 而没有名称空间,我该怎么办。

<RVE xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><RVE>

我用 excel xml 测试了它,没有错误,我注意到的不同之处在于它没有这个 xmlns: xsi 和 xmlns: xsd

我的模型类:

[XmlType("RVE")]
public class ApontamentoExportarviewmodel
{
    [XmlElement(ElementName = "ITEM")]
    public int Item { get; set; }

    [XmlElement(ElementName = "EQUIPAMENTO")]
    public int Equipament{ get; set; }
}

我的格式化程序类:

public class XmlActionResult<T> : ActionResult
{
    public XmlActionResult(List<T> data)
    {
        Data = data;
    }

    public List<T> Data { get; private set; }

    public override void ExecuteResult(ControllerContext context)
    {
        context.HttpContext.Response.ContentType = "text/xml";

        // Todo: Use your preferred xml serializer 
        // to serialize the model to the response stream :
        // context.HttpContext.Response.OutputStream

        ApontamentoExportarviewmodel apontamentoExportarviewmodel = new ApontamentoExportarviewmodel();

        int fileName = 0;
        if (Data is List<ApontamentoExportarviewmodel>)
        {
            var record = (Data as List<ApontamentoExportarviewmodel>).FirstOrDefault(); 
            if (record != null)
                fileName = record.Equipamento;
        }
        var cd = new System.Net.Mime.Contentdisposition
        {
            // for example foo.bak
            FileName = string.Format("MA_" + fileName + "_{0:yyyyMMdd_HHmm}.xml",DateTime.Now),// always prompt the user for downloading,set to true if you want 
            // the browser to try to show the file inline
            Inline = false,};

        var root = new XmlRootAttribute("meadinkent");
        XmlSerializer x = new XmlSerializer(Data.GetType(),root);
       context.HttpContext.Response.AppendHeader("Content-disposition",cd.ToString());
        x.Serialize(context.HttpContext.Response.OutputStream,Data);

    }
 }
 }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)