XML Serialization
- System.Xml.Serialization for r/w XML files.
- Objs (incl. custom objs) <-> XML files. + transmit objs bet. computers ~ Web Services.
- When XML Serialization? - when sending obj -> non-.NF-based app + do not need to serialize private members.
- greater interoperability - XML is a text-based file std - all dev envs handle processing XML files.
- more admisistrator friendly - viewed/edited ~ text-editor.
- XML can only serialize public data - not private.
- cannot serialize obj graphs - only objs.
- Serialize - 1) create a stream to hold serialized output. 2) constr. XmlSerializer, 3) XmlSerializer.Serialize().
- Deserialize - 1) Create stream to read serialized input, 2) XmlSerializer, 3) XmlSerializer.Deserialize().
- custom XML serializable class - 1) specify class as public, 2) specify all members that must be serialized as public, 3) create a parameterless constructor. (private + protected members will be skipped).
- XML Schema - defines the structure of an XML document.
- when 2 apps exchange XML files, you need an XML schema.
- XML Schema - if have one, run XML Schema Def Tool (xsd.exe) to produce class that is strongly typed to the schema. When an instance of such a class is serialized, the generated XML adheres to the XML schema. This makes it simple to create apps that interoperate with standards-based Web svcs.
- serialize a dataset - as per serializing an obj
No comments:
Post a Comment