Wednesday, October 17, 2007

Writing data into XML files

You can use XmlTextWriter to write XML. XmlTextwriter is an implementation of the XmlWriter class. This class provides number of validatins to make sure xml is well formed. Here is the code to create a XML file.

using System.Xml;

XmlTextWriter myXmlTextWriter = new XmlTextWriter("student.xml", null);

myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteDocType("students", null, "students.dtd", null);
myXmlTextWriter.WriteComment("This file represents a student in the institute");
myXmlTextWriter.WriteStartElement("student", null);
myXmlTextWriter.WriteAttributeString("category", "Bsc");
myXmlTextWriter.WriteAttributeString("course", "Computer Science");
myXmlTextWriter.WriteElementString("birthdate", null, "1979-05-22");
myXmlTextWriter.WriteStartElement("Name", null);
myXmlTextWriter.WriteElementString("first-name", "Shawn");
myXmlTextWriter.WriteElementString("last-name", "Tait");
myXmlTextWriter.WriteElementString("GPA", "4.55");


WriteStartDocument(Boolean) - writes the xml declaration with the version 1.0 and the standalone attribute.
WriteComment - writes a comment containing the specified text.
WriteStartElement - writes the specified start tag.
WriteElementString - writes an element containing a string value.
WriteEndElement - writes the specified end tag.
WriteAttributeString - writes an attribute with a specified value.

DevDay 2007

Yesterday I've been to DevDay 2007 organized by Sri Lanka .Net forum held at Mount Lavinia hotel. There were 4 interesting technical sessions and later the party. All the 4 sessions were great. It was worth to attend.

Discover Next Generation Visual Studio and .NET 3.5
An Adventure with C# 3.0 and LINQ
By: Chua Wen Ching (MVP - C#)

WPF, a new way of looking @ your Windows Applications
Silverlight: The web just got richer
By: T.N.C. Venkata Rangan (Microsoft Regional Director)

Tuesday, October 02, 2007

Rugby World Cup 2007 - Knockout Stage

Rugby World Cup 2007 first round is over and 8 teams were selected to play the second stage. This will be a knockout out stage and unbeaten team in next 3 games will get the opportunity to lift the cup and crown as RWC 2007 champs.

As the tournament started with a upset by Argentina beating host France, Argentina managed to continue their rhythm and finish the first round as the top of their pool. They will be a strong contender in the knockout stage and it'll be a very interesting quarterfinal Argentina Vs Scotland.
Fiji managed to enter to the second round by beating Wales. So they'll meet South Africa in their first match in the second round.

Other 2 quarterfinals will be Australia Vs England and New Zealand Vs France. New Zealand finished all their first round matches very promisingly and they are the favorites in this tournament. But their lack of performances in the big games is always a huge disadvantage for them and also France is seeking for an opportunity to cover their humiliation defeat by Argentina in the first round, so they'll play their hearts out in front of their own crowd, in their own grounds. Nevertheless as I said earlier this is the best NZ team in a world cup after 1992 So they'll smell the cup as no one else does.

Creating a new XML file using XMLDocument

Here is the XML file:

version="1.0" encoding="utf-8"?>
    <name>Michael Jones</

Here is the code to generate the XML file:

using System.Xml;

XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

// Create the root element
XmlElement rootNode = xmlDoc.CreateElement(
xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);

// Creating the parent node
XmlElement parentNode = xmlDoc.CreateElement(

// Create the required nodes
XmlElement eleId = xmlDoc.CreateElement(
XmlElement eleName = xmlDoc.CreateElement(

// retrieve the text
XmlText textId = xmlDoc.CreateTextNode("1");
XmlText textName = xmlDoc.CreateTextNode("Michael Jones");

// append the nodes to the parentNode without the value

// save the value of the fields into the nodes

xmlDoc.Save(Request.MapPath() + "Students.xml");