Using XmlSerializer to create an element with attributes and a value but no sub-element

后端 未结 1 1811
别跟我提以往
别跟我提以往 2020-11-30 13:25

Hopefully this should be an easy answer for someone out there (and possibly a dupe), but I can\'t seem to figure it out.

I need to output an element that looks like

相关标签:
1条回答
  • 2020-11-30 14:10

    I find the answer here: Xmlserializer - Control Element-Attribute Pairing (revised).

    Here is how to do it: mark the value property with the [XmlText] attribute.

    public class Quantity {
      // your attributes
      [XmlAttribute]
      public string foo;
    
      [XmlAttribute]
      public string bar;
    
      // and the element value (without a child element)
      [XmlText]
      public int qty;
    
    }
    
    0 讨论(0)
提交回复
热议问题