Views: 12.6K
Replies: 3
Archived
|
How can I generate xml elements or attributes from a custom collection? Hi:
I have a custom collection and items have two properties. I want to serialize one property to an xmlelement and another property to an xmlattribute. How can I do this? Thanks. Best Regards. Volkan Genç, May 16, 2011
|
|
Reply 1Wow! I have one of the most trending game that you loves to play online most of the kids loves to play fireboy and watergirl online game without any download and login the goal of the game is to collect the gems and run more to achieve the gems and avoid to pass through the red blue and green lake.
Himanshu Mishra, May 28, 2018
|
|
Reply 2Give the [Serializable] attribute to appropriate property such a way you can serialize it by selective members. namespace SampleApp [XmlAttribute("myAttribute")] Rajesh Shanmugam, Jun 01, 2011
|
|
Reply 3To accomplish your goal add attributes to the properties in your collection. When the XML Serializer writes the XML it will create the requested node type.
Here's a sample in C# using System.Xml.Serialization; namespace SampleApp { [XmlRoot("MyCollection")] class CustomCollection { [XmlElement("myElement")] public string MyElementProperty { get; set; } [XmlAttribute("myAttribute")] public string MyAttributeProperty { get; set; } } } Steve Steve Thompson, May 17, 2011
|