loresoft-commits Mailing List for LoreSoft.com Libraries
Brought to you by:
pwelter34
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
---|
From: <pwe...@us...> - 2003-10-22 23:07:51
|
Update of /cvsroot/loresoft/ComSerialization/Documentation In directory sc8-pr-cvs1:/tmp/cvs-serv25007/Documentation Added Files: index.htm Log Message: Updates --- NEW FILE: index.htm --- <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>The ComSerialization component c</title> <style> BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt } H2,H3,H4,H5 { color: #ff9900; font-weight: bold; } H2 { font-size: 13pt; } H3 { font-size: 12pt; } H4 { font-size: 10pt; color: black; } PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; } CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; } </style> <link rel="stylesheet" type="text/css" href="http://www.codeproject.com/styles/global.css"> </head> <body> <h2>Introduction</h2> <p>The ComSerialization component can be used to serializes and deserializes COM objects into and from XML documents. Serialization is the process of converting an object's public properties and fields to a serial format (in this case, XML) for storage or transport. Deserialization restores the object to its original state from the XML output. You can think of serialization as a way of saving the state of an object into a buffer.</p> <h2>XmlSerializer Object</h2> <p><b>Public Methods</b></p> <li><b>Deserialize</b>: Deserializes an XML document to the object reference</li> <li><b>Serialize</b>: Serializes an object into an XML document</li> <p><b>Public Properties</b></p> </li> <li><b>CollectionAddMethod</b>: The name of the collection method that will return a reference to a collection item </li> <li><b>IgnoreList</b>: Semicolon delimited list of properties to ignore when serializing </li> <li><b>LastError</b>: The description of the last error that occurred </li> <h2>Serialize Method</h2> <p><b>Description</b></p> <blockquote> <p>Serializes an object into an XML document</p> </blockquote> <p><b>Syntax</b></p> <blockquote> <p><strong>Public Function Serialize</strong>( _<br> <strong>ByVal </strong><i>SourceObject</i> <strong>As</strong> <b>Object</b> _<br> )<strong> As <b>String</b></strong></p> </blockquote> <p><b>Parameters</b></p> <blockquote> <p><i>SourceObject</i> <br> A reference to an object to be serialized </p> </blockquote> <p><b>Return Type</b></p> <blockquote> <p>Returns an XML string representing the serialization of the object</p> </blockquote> <p><b>Remarks</b></p> <blockquote> <p>The serialize method will serialize any readable property that does not have any parameters. If the property returns an object, it will be recursively serialized. Collections that support NewEnum will also be serialized. <br> <br> Use the IgnoreList to exclude spesific properties from serialization. <br> <br> <b>Warning: Be sure to ignore properties that could cause an infinite loop, like parent.</b><br> <br> <b>Serialization Limitations</b><br> <br> Arrays and User Defined types not supported. </p> </blockquote> <p><b>Example</b></p> <blockquote> <pre lang=vb > Dim oXmlSerializer As ComSerialization.XmlSerializer Dim oProject As Project Dim oTask As Task Dim oUser As User Dim sXML As String 'create object Set oProject = New Project 'add some test data With oProject .ProjectName = "Test" .ProjectID = 1 .ProjectDescription = "This is a test" .TestDate = Now 'example collection Set oUser = .Users.Add oUser.FirstName = "Me" oUser.LastName = "Moe" oUser.Email = "me...@mo..." oUser.Phone = "555-1212" Set oUser = Nothing 'example collection Set oTask = .Tasks.Add oTask.TaskID = "123" oTask.TaskName = "test task" 'example child object oTask.User.FirstName = "Test" oTask.User.LastName = "Person" Set oTask = Nothing 'example collection Set oTask = .Tasks.Add oTask.TaskID = "222" oTask.TaskName = "second test task" 'example child object oTask.User.FirstName = "Second" oTask.User.LastName = "Person" Set oTask = Nothing End With 'create serialization object Set oXmlSerializer = New ComSerialization.XmlSerializer 'return xml sXML = oXmlSerializer.Serialize(oProject) Debug.Print sXML </pre> </blockquote> <h2>Deserialize Method</h2> <p><b>Description</b></p> <blockquote> <p>Deserializes an XML document to the object reference</p> </blockquote> <p><b>Syntax</b></p> <blockquote> <p><strong>Public Function Deserialize</strong>( _<br> <strong>ByVal </strong><i>TargetObject</i> <strong>As</strong> <b>Object</b> _<br> <strong>ByVal </strong><i>sXML</i> <strong>As</strong> <b>Object</b> _<br> )<strong> As <b>Boolean</b></strong></p> </blockquote> <p><b>Parameters</b></p> <blockquote> <p><i>TargetObject</i> <br> A reference to an object to be deserialized </p> <p><i>sXML</i> <br> XML string to deserialize to the object</p> </blockquote> <p><b>Remarks</b></p> <blockquote> <p><strong>Deserialization Limitations</strong></p> <ol> <li>Arrays and User Defined Types not supported </li> <li>Child objects will deserialize only if the property returns a valid reference to the object </li> <li>To deserialize a collection, the add method of the collection must return a valid reference to an object that has been added to the collection. The add method must not have any required parameters. Note that collection keys will be lost on deserialization. You may specify an alternate to the add method by setting CollectionAddMethod property</li> </ol> </blockquote> <p><b>Example</b></p> <blockquote> <pre lang=vb > Dim oXmlSerializer As ComSerialization.XmlSerializer Dim oProject As Project Set oXmlSerializer = New ComSerialization.XmlSerializer 'create the XmlSerializer Set oProject = New Project 'create a new object reference 'call deserialize passing in object reference and xml 'sXML is the xml string that was return from Serialize oXmlSerializer.Deserialize oProject, sXML 'oProject's state should now be the same as it was when we serialized it </pre> </blockquote> <p> <h2>Conclusion</h2> <p>Hope you find this component usefull.</p> <p>Paul Welter<br> <a href="http://www.loresoft.com">http://www.loresoft.com</a></p> </body> </html> |