New Video Code Warmup - XML
Yet another blockbuster video code warmup. This one is on XML. Most of us find ourselves working with XML. Whoever thought it up was a genius. It's very easy to work with using the .NET framework. In this video we simply create a stream using the XmlWriter class and write XML directly out to the console. After you watch just a little bit of the video you will get the idea of how easy it is. Of course should you need to work with DOM properties you will have to use the XML Document class but the XmlWriter Class works fast as heck for getting the job done!
You can view the video by clicking Here.
This is a screen shot of what the console looks like when you are done (I have my console background white and font color navy):

Here is the code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace CodeWarmUp_xml{
class Program
{
static void Main(string[] args){
XmlWriterSettings settings = new XmlWriterSettings();settings.Indent = true;
using (XmlWriter writer = XmlWriter.Create(Console.Out,settings)){
writer.WriteStartElement("Categories");writer.WriteStartElement("DotNet");writer.WriteStartElement(
"Instructor");writer.WriteAttributeString("Name", "Jennifer Campion");writer.WriteEndElement();
writer.WriteStartElement("Instructor");writer.WriteAttributeString(
"Name", "Mike Palermo");writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteStartElement("Cisco");writer.WriteStartElement("Instructor");writer.WriteAttributeString(
"Name", "Mike Storm");writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}
}

Reader Comments