How to add attributes for C# XML Serialization

前端 未结 4 1934
心在旅途
心在旅途 2020-11-30 03:42

I am having an issue with serializing and object, I can get it to create all the correct outputs except for where i have an Element that needs a value and an attribute. Here

4条回答
  •  鱼传尺愫
    2020-11-30 04:30

    The string class doesn't have a type property, so you can't use it to create the desired output. You should create a Document class instead :

    public class Document
    {
        [XmlText]
        public string Name;
    
        [XmlAttribute("type")]
        public string Type;
    }
    

    And you should change the Document property to type Document

提交回复
热议问题