More servicesWindows Live
HomeHotmailSpacesOneCare
 
MSN
Sign in
 
 
Spaces home  John Stewien's Road To S...ProfileFriendsFilesMore Tools Explore the Spaces community

Public folders

Folders shared with the world

John Stewien's Road To Somewhere Else

Programming in WPF (.NET 3.0) and moving to Taiwan
7/15/2008

C# Formatting XmlSerializer Output

 

So today I’m writing an app that loads and writes data to and from XML files, Excel Files, and Oracle Databases. An integration application you might say. Naturally I picked C# for the job as the thought of debugging a big hairy Perl script didn’t fill me with joy. Unfortunately my work PC only has Visual Studio 2003 on it, but what can you do?

One of the things I wanted to do was load an XML file, modify some parts of it, and then write it out again with just the parts changed that I wanted changed. Fortunately I had an XSD for the XML file so I used the VS2003 xsd.exe utility to convert it to a C# .cs file. Unfortunately it did a terrible job and created C# class hierarchies that were a bit messy. So I went through and hand modified the C# code until I ended up with something I liked.

Right, I deserialized the XML file, modified the data, and wrote it out again just using the simple XmlSerializer class in C#.

What I wanted was this header:

<?xml version="1.0" encoding="UTF-8" ?>
<ReferenceData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="T:\ ReferenceData.xsd">

What I got was this:

<?xml version="1.0"?>
<ReferenceData xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

And to top it off the output file had double space as the indentation instead of tabs. To fix all this first of all I modified the serializable class to generate the noNamespaceSchemaLocation attribute:

[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public classReferenceData {
     [XmlAttribute(AttributeName="noNamespaceSchemaLocation",
             Namespace="http://www.w3.org/2001/XMLSchema-instance")]
     public stringnoNamespaceSchemaLocation = @"T:\ReferenceData.xsd";

Then I changed the serialization to encode in UTF-8, indent using single tab spaces, and set the namespace the way I wanted it set:

XmlSerializer serializer = newXmlSerializer(typeof(Xml.ReferenceData));
XmlTextWriter stream = newXmlTextWriter(saveFileDialog1.FileName, System.Text.Encoding.UTF8);
using(Stream baseStream = stream.BaseStream){
    stream.Formatting = Formatting.Indented;
    stream.IndentChar = '\x09';
    stream.Indentation = 1;

    //Create our own namespaces for the output
  
XmlSerializerNamespaces ns = newXmlSerializerNamespaces();
    ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    serializer.Serialize(stream, referenceData, ns);
}

Then I got the output I wanted.

7/6/2008

Office Design

We've been thinking about office design for the new company. There's a few things that come to mind:

People have engaged discussions when doing something else, for example when playing golf business executives will often have very productive discussions. In light of this I'm thinking that the meeting room should have a pool table (8-ball, 9-ball, billiards, snooker, etc), so that people can play a game while having productive discussions.

Work stress can lead to making mistakes, people need to feel relaxed so that they can concentrate on the job, therefore I think the office should have hot tubs (spas, artificial hot springs), for people to work in, this would also be good for meetings, however we will need to find some floating waterproof laptops.

We also needs plants, heating, cooling, a location that is near a Starbucks, near the underground train, etc

7/4/2008

More Pictures From Adelaide

Here are my parents waiting for me at the airport. Jasmine arrived with Violet from Taiwan, and I arrived from Perth.

DSC02789

 

Here's Jasmine at lunch with a friend, who is also my best friend's fiancee:

DSC02796

 

Here I am with Violet and my best friend Ian:

DSC02797

 

Here are Violet and I feeding the swans:

DSC02801

 

Here's Jasmine, Violet and I at the Torrens River, Adelaide:

DSC02808

 

Here I am pushing Violet along in North Adelaide:

DSC02821

 

What the?

DSC02836

 

Here's my best friend with his fiancee from Taiwan:

DSC02843

 

Here's Violet waiting for lunch:

DSC02855

 

After lunch here's Violet with her great grandmother:

DSC02866

7/3/2008

Baby Stunt

Violet climbing the couch. Violet was not harmed as a result of this stunt. The minor harm that occurred later was due to something else and was not stunt related.

 

Trip to Adelaide

Went on a trip to Adelaide to fix up some things, and to catch up with family and friends. Unfortunately I didn't have time to catch up with all my friends. Jasmine, Violet and I are now all on the same medicare card though. For some reason it seems like a nice feeling to pull out my medicare card and see the names of my family all on there.

 

Here's all my immediate family including my sister's family unit:

IMG_0278

 

Violet got to meet her cousins for the first time:

IMG_0069

 

She's a big baby, but hopefully she won't get as big as her grandfather:

IMG_0219

 

Here's a picture of my beautiful wife and daughter together:

 IMG_0234_enhanced

 

While in Adelaide we travelled about by bus and train:

IMG_0087

IMG_0270

 

Lunch times can be tricky:

IMG_0091

 

A high chair is recommended:

IMG_0176

 

Got to watch out at the pub for baby grabbing things:

IMG_0226

 

At the end of the day a bath is good:

IMG_0080

 

Then maybe watch some tv:

IMG_0215

 

We had some fun times:

IMG_0209

 

Note the teeth:

IMG_0181

 

But at the end of the day a rest is good:

IMG_0262

View more entries
 
View space
(no name)
View space
Boris
View space
Jasmine