简体   繁体   中英

XML attributes are ignored upon serialization

I am having a weird issue I am banging my head against...

I have a class like this:

[XmlRoot("DoesntWork")]
class Root
{
  [XmlElement(ElementName="WontWork", Order=1)]
  public string xmlOutPropertyName
  {...}
}

and I am serializing with this:

textBox1.Clear();
Root rt = new Root();
rt.xmlOutPropertyName = "[0000000001]";
XmlSerializer serializer = new XmlSerializer();
textBox1.Text = serializer.Serialize(rt);

but I always get xml that returns the names of class and property and not the name I want.

<Root>
  <xmlOutPropertyName>[0000000001]</xmlOutPropertyName>
</Root>

Any idea why this is happening??

愚蠢的错误,我没有注意并使用了错误的序列化库。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM