Game Development Reference
In-Depth Information
Finally, let's create the XmlSerializer object to deserialize the XML into usable
objects (see Listing 12.9).
}
[XmlRoot("Characters")]
public class CharacterList
{
[XmlElement("CharacterData")]
public CharacterData[] list;
static public CharacterList FromXml(Stream stream)
{
XmlSerializer serializer = new XmlSerializer(typeof
(CharacterList));
return serializer.Deserialize(stream) as CharacterList;
}
}
class autoxml
{
static CharacterList characters;
static void Main (string[] args)
{
Stream reader = new FileStream(args[0], FileMode.Open);
characters = CharacterList.FromXml(reader);
// Our xml is fully parsed now, so we can do whatever we need
// with the data
foreach (CharacterData data in characters.list)
Console.WriteLine(data);
}
}
Listing 12.9. Using XmlSerializer.Deserialize() to parse (autoxml.cs).
Now, wasn't that much easier than a DOM-based approach? We can do bet-
ter. Why have an extra step for XSLT conversion? Let's just embed it (see List-
ing 12.10)!
class autoxml2
{
// The embedded XSL document
static string xslt = @"
<xsl:stylesheet xmlns:usos=""urn:schemas-microsoft-com:office
:spreadsheet""
version=""1.0""
xmlns : xsl = " " http :// www . w3 . org /1999/ XSL / Transform " "
xsl:version=""1.0"">
<xsl:output indent=""yes"" />
<xsl:template match=""/"">
<Characters>
<xsl:for-each select=""/usos:Workbook/usos:Worksheet/usos:
Table/usos:Row"">
Search WWH ::




Custom Search