0

I think this name space is giving a problem when the user exports to a SAP module, how could I remove it. How would I do to leave only the XMLTYPE, without the name space.

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

I tested it with excel xml and there is no error and the difference I noticed is that it didn’t have this xmlns: xsi and xmlns: xsd

My Model class:

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

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

My formatter class:

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);

    }
 }
 }
AllPower
  • 175
  • 1
  • 4
  • 16
  • Is your output meeting the schema? If an aplication is having issues reading than probably your output is not meeting the schema requirements. When generating XML files that have a schema you should alway validate output with a schema check before distributing. – jdweng Mar 05 '21 at 22:06
  • Both namespace definitions should have no direct effect on the `` element. Maybe the namespaces are used in one of its children? – zx485 Mar 05 '21 at 22:29
  • Do [XmlSerializer: remove unnecessary xsi and xsd namespaces](https://stackoverflow.com/q/760262/3744182) or [Omitting all xsi and xsd namespaces when serializing an object in .NET?](https://stackoverflow.com/q/625927/3744182) answer your question? – dbc Mar 07 '21 at 14:32

0 Answers0