12/4/2023 0 Comments Set name of element![]() ![]() This has the side effect of generating one more inner element representing the list itself. Using (StreamReader reader = new StreamReader(stream)) Using (StreamWriter writer = new StreamWriter(stream)) Using (Stream stream = new MemoryStream()) XmlSerializer serializer = new XmlSerializer(typeof(SongGroup)) This example uses a SongGroup class to wrap the list so that you can give alternate names to the items within. If the list item corresponds to an object. The degree of control you are asking for is not possible without a wrapping class. If the list item corresponds to a data type property, the tag is the property name with Item concatenated to the end. Here is my updated response based on your clarification. If this is the root element of the document, you can use. Using (TextWriter textWriter = new StreamWriter("filename"))Īpparently, the XmlRoot() attribute doesn't rename the object in a list context. XmlSerializer serializer = new XmlSerializer(typeof(List)) Here's the serialization code: public static bool SaveSongs(List songs) I'm actually serializing a list of Song objects in the XML. I don't wish to create/traverse the DOM manually, so I was wondering if it could be achieved via a decorator. Is it possible to rename class-names via xml-attributes? So that the resultant xml should look like this: Say, in the above example, I wish to rename the class Song to g. I want to rename/remap the name of the class/object as well. In order to save space (and also semi-obfuscate the XML file), I decide to rename the xml elements: In mathematics, an element (or member) of a set is any one of the distinct objects that belong to that set.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |