CUAHIS-HIS
RSS

Navigation





Quick Search
»
Advanced Search »

PoweredBy

XML Serialization in Dot Net

RSS
Modified on 2009/05/25 11:56 by valentinedwv Categorized as Research
We can do XML serialization using the LiquidXML classes. (another xml serializer: http://www.codeplex.com/Xsd2Code)

Actually, LiquidXML.XmlObject base from which everythign is derived has the iXMLserializable interface implemented.

For each returned object, the developers need to implement a proxy class that implements the iXmlSerialier Basically,
Article:Customizing XML Serialization in .NET 2.0 Using the IXmlSerializable Interface

Blog Entires: http://www.hanselman.com/blog/CategoryView.aspx?category=XmlSerializer&page=1

Look at Link to XSD:

Start of Class


[XmlSchemaProvider("MySchema")]
public class SongStream : IXmlSerializable
{

GenSchema


Public Function GetSchema() As _
    System.Xml.Schema.XmlSchema _
    Implements IXmlSerializable.GetSchema
    Throw New System.NotImplementedException()
  End Function


XXmlSchemaProvider

      
public static XmlQualifiedName MySchema(XmlSchemaSet xs)
    {
     // This method is called by the framework to get the schema for this type.
     // We return an existing schema from disk.

     XmlSerializer schemaSerializer = new XmlSerializer(typeof(XmlSchema));
     string xsdPath = null;
     // NOTE: replace the string with your own path.
     xsdPath = System.Web.HttpContext.Current.Server.MapPath("SongStream.xsd");
     XmlSchema s = (XmlSchema)schemaSerializer.Deserialize(
         new XmlTextReader(xsdPath), null);
     xs.XmlResolver = new XmlUrlResolver();
     xs.Add(s);

     return new XmlQualifiedName("songStream", ns);
    }





[XmlSchemaProvider("MethodToGetSchema")]

WriteXML


Public Sub WriteXml(ByVal writer As XmlWriter) _
      Implements IXmlSerializable.WriteXml     
      writer.WriteStartElement _
         ("employee", "urn:devx-com")       
      writer.WriteAttributeString _
         ("firstName", _firstName)        
      writer.WriteAttributeString _
         ("lastName", _lastName)     
      writer.WriteAttributeString _
         ("address", _address)
      writer.WriteEndElement()
  End Sub

ReadXML

   
 void IXmlSerializable.ReadXml(System.Xml.XmlReader reader)
    {
     throw new System.NotImplementedException();

    }

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam.