Zdroj:
https://msdn.microsoft.com/en-us/library/58a18dwa(v=vs.110).aspx
XmlIgnore
[XmlIgnore]
public int PropertyName{get; set;}
XmlRoot
[XmlRoot("korenovy_tag")]
public class XmlRootElement {get; set;}
<korenovy_tag>
...
</korenovy_tag>
XmlText
Zdroj:
http://stackoverflow.com/questions/3638113/using-xml-class-attributes-how-to-represent-an-xml-tag-with-both-inner-text-and
[XmlText()]
public string Text {get; set;}
<tag>text</tag>
Poznámka: Pokud nemá property setter tak se hodnota do XML při serializaci nezapíše.
XmlAttribute
Zdroj:
http://stackoverflow.com/questions/3638113/using-xml-class-attributes-how-to-represent-an-xml-tag-with-both-inner-text-and
[XmlAttribute("skutecny_nazev_tagu")]
public string NazevProperty {get; set;}
<tag skutecny_nazev_tagu="hodnota">
XmlElement
[XmlElement("skutecny_nazev_tagu")]
public int Value {get; set;}
<skutecny_nazev_tagu>1</skutecny_nazev_tagu>
XmlArray a XmlArrayItem
[XmlArray("collection_name")]
[XmlArrayItem("collection_item_name")]
public List<ItemType> Items { get; set; }
<colection_name>
<collection_item_name Id="1" />
<collection_item_name Id="2"/>
....
</colection_name>
Vynechat prázdné hodnoty
Zdroj:
http://stackoverflow.com/questions/5818513/xml-serialization-hide-null-values
Property s názvem ShouldSerialize{PropertyName} kde PropertyName je název property která by se měla nebo neměla serializovat.
public bool ShouldSerializeMyNullableInt()
{
return MyNullableInt.HasValue;
}
nebo{PropertyName}Specified
Serializace bez Namespace
Zdroje:
http://stackoverflow.com/questions/8061106/xml-serialization-remove-namespace
var xns = new XmlSerializerNamespaces();
var serializer = new XmlSerializer(users.GetType());
xns.Add(string.Empty, string.Empty);
//...
serializer.Serialize(stream, users, xns);
Žádné komentáře:
Okomentovat