Scott Miller

Appsguild - Software craftsmanship, project management, and the biz of software

  Home  |   Contact  |   Syndication    |   Login
  153 Posts | 3 Stories | 177 Comments | 72 Trackbacks

News



Article Categories

Archives

Image Galleries

Best Blogs

Podcasts

Scott's links

No, that is not the name of my game, just The Bloodletting.

I started creating my XML data files for character cards, etc. One of the design features of the game is to allow complete customization of the cards by changing the XML file. This will allow me to add cards later (can you say "expansion deck"), and also allow others to do so. After all, no game stays in scope for long; it gets bigger and bigger. Because the XML files can be customized, assuring that they are in the correct format and well formed is important. So I decided to create a schema to test validation against.

I can create XML off the top of my head, but I don't have the XSD structure down as well. And the Express version of Visual C#.Net doesn't have the XML Designer I am used to using in the Pro version. So how to create my XSD?

I decided to load the XML into a dataset and infer the schema from the file, finally writing it back out to the XSD file. You can do this using the XMLTextWriter too, but it was easier just to put it in a dataset. This also solved my earlier question on whether I could use XML and datasets in the Express version of C#.Net (in the Standard/low end versions of C#.Net 2003 you couldn't do alot of those things because they were disabled).

This also required frequent access of the help file, which, after some earlier rough spots, turned out to be very helpful.

Here is the code I used:

private string XmlPath = @"..\..\XMLData\";
private string XmlFileName = "CharacterCards.xml";
private string XmlSchemaFileName = "CharacterCards.xsd";
private void InferXMLSchema()
{
DataSet dataSet = new DataSet();
dataSet.ReadXml(XmlPath + XmlFileName, XmlReadMode.InferSchema);
System.IO.StreamWriter writer = new System.IO.StreamWriter(XmlPath + XmlSchemaFileName);
dataSet.WriteXmlSchema(writer);
writer.Close();
}

posted on Monday, May 22, 2006 3:57 AM