1 year ago
#253915
FAYCAL KADRI
Add XmlAttribute to XmlElement in c# class
I want to add an Xml Attribute to my class property that is XmlElement:
[XmlRoot(ElementName = "item")]
public class Item
{
[XmlElement(ElementName = "title")]
public string Title { get; set; }
[XmlElement(ElementName = "description")]
public string Description { get; set; }
[XmlElement(ElementName = "link")]
public string Link { get; set; } //content webpage link
[XmlElement(ElementName = "pubdate")]
public string PubDate { get; set; }
[XmlElement(ElementName = "valid")]
public string Valid { get; set; }
[XmlElement(ElementName = "videoAssertId")]
***//ADD here an XmlAttribute with value to this element (videoAssertId)***
public string VideoAssertId { get; set; }
[XmlElement(ElementName = "durableAppId")]
public string DuarableAppId { get; set; }
[XmlElement(ElementName = "seriesAssertId")]
public string SerieAssertId { get; set; }
}
}
RESULT SHOULD BE
<item>
<title>xxxxxx</title>
<description>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.</description>
<link>https://link/</link>
<pubdate>2002-10-13T09:00Z</pubdate>
<valid>start=2002-10-13T09:00Z;end=2002-10-17T17:00Z;scheme=W3C-DTF</valid>
<videoAssertId **provider=xxx**>5241112554</videoAssertId>
<durableAppId>xxxxxxxx</durableAppId>
</item>
The attribute 'provider' should appear in 'VideoAssertId' element. Some one know how todo that please, I'm loosing my mind with that?
c#
xml-serialization
0 Answers
Your Answer