XmlSerializer generates file with empty space before the closing tag

0

I'm using the following code to generate an xml:

public bool SerializarObjeto(object o, string pathArquivo)
{
    var xns = new XmlSerializerNamespaces();

    XmlSerializer writer = new XmlSerializer(o.GetType());

    StreamWriter file = new StreamWriter(pathArquivo);
    writer.Serialize(file, o, xns);
    file.Close();
    return true;
}

Generate the following result in a given file:

<item iis="078906590000500400348059" produzido="2016-07-15T07:34:54" />

My problem:

I need you not to leave the space before closing the tag:

As it leaves: " />
How it should exit: "/>

Thank you.

    
asked by anonymous 20.07.2016 / 07:23

1 answer

1

Well, I do not know any options in .NET XML objects to modify this behavior, I believe you will need to make a code in your method to do this after serialization, something like:

var xml = System.IO.File.ReadAllText(pathArquivo);
xml = xml.Replace(" />","/>");
System.IO.File.WriteAllText(pathArquivo, xml);

Remember that if you do some digital signature in XML, you have to do this replace BEFORE signing, since it will change the contents of the

    
21.07.2016 / 12:14