如何解决从 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 举报,一经查实,本站将立刻删除。