C# and XML Primer by Jonathan Hartwell
Author:Jonathan Hartwell
Language: eng
Format: epub
Publisher: Apress, Berkeley, CA
The XML looks no different than what we would have created using XmlDocument or LINQ to XML, yet it took only a few lines of code to do so. You may have noticed the namespaces on the Book element. Since those are typically the default namespaces, the XmlSerializer will add those to the root element. Another thing to note is that the root element is the name of our model type.
So how does this work under the hood? The XmlSerializer uses reflection to get the properties of a given serializable class and then creates elements based on those properties. Since this is all handled by reflection, there are several attributes that can be used to iterate on that will perform various actions. For instance, there is the XmlAttribute class , which is used on a property that should have some sort of attributes. There is also an XmlIgnore attribute, which can be used to indicate that a specific property should not be serialized. In Chapter 5, we will create our own XmlSerializer so that we can get a better understanding of exactly how it works.
I just gave examples of other attributes that can be used in a given model. Let's use both of them and see what the output is. We will revisit our book model again. This time, let's not serialize the year that the book was written and let's also add a propety to the name to indicate that a movie has been made based on this book. Our Book class now changes to the following model:
[Serializable]
public class Book
{
[XmlAttribute(AttributeName = "Movie")]
public bool IsMovie { get; set; }
public string Title { get; set; }
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12575)
Hello! Python by Anthony Briggs(9916)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9796)
The Mikado Method by Ola Ellnestam Daniel Brolund(9779)
Dependency Injection in .NET by Mark Seemann(9340)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8301)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Grails in Action by Glen Smith Peter Ledbrook(7697)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(7089)
Microservices with Go by Alexander Shuiskov(6858)
Practical Design Patterns for Java Developers by Miroslav Wengner(6777)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6714)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6419)
Angular Projects - Third Edition by Aristeidis Bampakos(6125)
The Art of Crafting User Stories by The Art of Crafting User Stories(5650)
NetSuite for Consultants - Second Edition by Peter Ries(5584)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5392)
Kotlin in Action by Dmitry Jemerov(5066)
