Skip to content

Commit

Permalink
Merge pull request #117 from allcoolusernamesaregone/master
Browse files Browse the repository at this point in the history
Use XmlSerializerNamespaces to remove the namespace attributes
  • Loading branch information
zivillian authored Aug 24, 2024
2 parents 50b63d9 + bd5c916 commit 51937ab
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/ism7mqtt/ISM7/Protocol/XmlPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ namespace ism7mqtt.ISM7.Protocol
public abstract class XmlPayload : IPayload
{
private static readonly ConcurrentDictionary<Type, XmlSerializer> _serializers = new ConcurrentDictionary<Type, XmlSerializer>();
private static readonly XmlSerializerNamespaces _serializerNamespaces = new XmlSerializerNamespaces();

static XmlPayload()
{
_serializerNamespaces.Add("", "");
}

public byte[] Serialize()
{
using var sw = new Utf8StringWriter();
var xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings {Indent = false});

var serializer = _serializers.GetOrAdd(GetType(), x => new XmlSerializer(x));
serializer.Serialize(xmlWriter, this);
serializer.Serialize(xmlWriter, this, _serializerNamespaces);
sw.Flush();
var xml = sw.ToString();
return Encoding.UTF8.GetBytes(xml);
}

public abstract PayloadType Type { get; }
}
}
}

0 comments on commit 51937ab

Please sign in to comment.