Game Development Reference
In-Depth Information
<xsl:if test=""position()!=1"">
<CharacterData >
<xsl:for-each select=""usos:Cell"">
<xsl:variable name=""cellPos"" select=""position()"" />
<xsl:element name=""{../../usos:Row[1]/usos:
Cell[ ￿ cellPos]/usos:Data}"">
<xsl:value-of select=""usos:Data"" />
</xsl:element>
</xsl:for-each>
</CharacterData >
</xsl:if>
</xsl:for-each>
</Characters>
</xsl:template>
</xsl:stylesheet>
";
static CharacterList characters;
static void Main (string[] args)
{
// Create a memory stream for holding the transformed XML
Stream xformedStream = new MemoryStream();
// Transform the original XML document in memory
var xform = new XslCompiledTransform();
xform.Load(XmlReader.Create(new StringReader(xslt)));
xform.Transform(args[0], null, xformedStream);
// Reset stream position to beginning, so it can be read
xformedStream.Position = 0;
characters = CharacterList.FromXml(xformedStream);
// 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.10. Embedding the XSLT step (autoxml2.cs).
Now, we can just execute the utility directly on the XML that Excel spits out:
autoxml2.exe CharacterData.xml .
There is a tool worth mentioning that is included with .NET: xsd.exe ,which
can automatically generate C# classes from XML schemas. Additionally, you can
generate the initial XML schema definition (XSD) from the XML document itself.
When we use xsd.exe on our transformed document from Listing 12.5 we get
Listing 12.11.
<?xml version="1.0" standalone="yes"?>
< xs:schema id =" Characters" xmlns = " " xmlns:xs = " http: // www . w3 . org /2001
/ XMLSchema " xmlns:msdata=" urn:schemas - microsoft - com:xml - msdata " >
<xs:element name="Characters" msdata:IsDataSet="true"
msdata:Locale="en-US">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
Search WWH ::




Custom Search