I haven’t found any information on this, maybe someone could help.
I have an XML (simplified for convenience):
<content>
<field1>value</field1>
<field2>
<field3>value</field3>
</field2>
</content>
I try to deserialize it using such classes:
[XmlRoot("content")]
public class Content
{
[XmlElement]
public List<Item> Fields { get; set; }
}
public class Item
{
[XmlElement]
public List<Item> Fields { get; set; }
[XmlText]
public String Value { get; set; }
}
I have two questions:
-
Can I get the actual name of the field? Like
[XmlName] string name;in the Item class? Or some kind of an attribute for the class itself? It is not possible to set the node name to “field” and add “type” attribute, for some reasons 😉 While the actual class and serialization process is really complicated, I’d prefer not to implement my own serializer. -
Can I add a wildcard like [XmlElement(“field*”)]? I can’t test it until I know the answer to the first question, so if there is a better option, I’d love to know it as well.
Thanks.
The only answer here is that it’s, unfortunately, not possible.
As a result we have written our own serialization routine.