Description
I need to process some XML input which has HTML code in some tags. For these tags I want the raw content to process it later. I followed this answer on Stackoverflow and used XmlElement as member which works fine in most cases. The only problem I'm facing are self closing tags.
Reproduction Steps
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class Program
{
public static void Main()
{
var serializer = new XmlSerializer(typeof(Root));
var obj1 = serializer.Deserialize(new StringReader(@"<Root><Description><p>test</p></Description><Name>Test</Name></Root>"));
// Description: "Element, Name=\"p\""
// Name: "Test"
var obj2 = serializer.Deserialize(new StringReader(@"<Root><Description></Description><Name>Test</Name></Root>"));
// Description: null
// Name: "Test"
var obj3 = serializer.Deserialize(new StringReader(@"<Root><Description/><Name>Test</Name></Root>"));
// Description: "Element, Name=\"Name\""
// Name: null
}
public class Root
{
public XmlElement Description { get; set; }
public string Name { get; set; }
}
}
Expected behavior
obj2 and obj3 should be equal.
Actual behavior
obj1 and obj2 are ok (obj2.Description == "" would be better) but in obj3 the Description member is greedy and contains the Name part.
Regression?
No response
Known Workarounds
No response
Configuration
I have tested it on .NET 5 and .NET 7 without differences.
Other information
No response
Description
I need to process some XML input which has HTML code in some tags. For these tags I want the raw content to process it later. I followed this answer on Stackoverflow and used
XmlElementas member which works fine in most cases. The only problem I'm facing are self closing tags.Reproduction Steps
Expected behavior
obj2andobj3should be equal.Actual behavior
obj1andobj2are ok (obj2.Description == ""would be better) but inobj3theDescriptionmember is greedy and contains theNamepart.Regression?
No response
Known Workarounds
No response
Configuration
I have tested it on .NET 5 and .NET 7 without differences.
Other information
No response