How can use XML Serialization in VB.Net and C#?

Xml-tool-iconAs you know there are different types of machines and OS in the world that they have to connect to each other and transfer data but each system has own structure and may cannot understand the data that are coming from other system(s), but technology has solved it for them! One of the solutions is XML

What is XML?

XML  (Extensible Markup Language) is a format that was designed to transport and store data.Both machine and human can understand XML.

If you want to learn more about the XML I suggest you to go this link.

Before start you must import these classes:

[VB.Net]

Imports System.IO
Imports System.Xml.Serialization

[C#]

using System.IO;
using System.Xml.Serialization;

[VB.Net]

 Private Sub CreateXML()
        Dim OFileStream As FileStream = _
New FileStream("C:/CodingTips.XML", _
        FileMode.Create)
        Dim Oxmlsr As XmlSerializer = _ 
New XmlSerializer(GetType(DateTime))
        Oxmlsr.Serialize(OFileStream, System.DateTime.Now.ToString)
        OFileStream.Close()
    End Sub

[C#]

private void CreateXML()
{
    FileStream OFileStream = new FileStream("C:/CodingTips.XML",_
 FileMode.Create);
    XmlSerializer Oxmlsr = new XmlSerializer(typeof(DateTime));
    Oxmlsr.Serialize(OFileStream, System.DateTime.Now.ToString());
    OFileStream.Close();
}


Categories: .Net

Tags: , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: