Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Xml;
- // 0 == name
- // 1 == val
- // -1== invalid
- class Constant {
- string[,] data;
- //int getName(string s) {
- //om nom nom
- //}
- int getIndex(string s) {
- switch (s) {
- case "name":
- return 0;
- //break;
- case "val":
- return 1;
- //break;
- default:
- return -1; //Bad
- }
- }
- public string this[int pos, string field]{
- get{
- return data[pos, getIndex(field)];
- }
- set{
- data[pos, getIndex(field)] = value;
- }
- }
- public Constant(int size) {
- data = new String[size, 2];
- }
- }
- /*
- * 0 == name
- * 1 == font
- * 2 == vjustify
- * 3 == hjustify
- * 4 == fontflags
- * 5 == styleflags
- * 6 == textcolor
- * 7 == disabledcolor
- * 8 == highlightcolor
- * 9 == hotkeycolor
- * 10== hyperlinkcolor
- * 11== shadowcolor
- * 12== shadowoffset
- */
- class Style {
- string[,] data;
- int getIndex(string s) {
- switch (s) {
- case "name":
- return 0;
- //break;
- case "val":
- return 1;
- //break;
- default:
- return -1; //Bad
- }
- }
- public string this[int pos, string field]{
- get{
- return data[pos, getIndex(field)];
- }
- set{
- data[pos, getIndex(field)] = value;
- }
- }
- public Style(int size) {
- data = new String[size, 2];
- }
- }
- class StyleFile {
- private int styleCount;
- private int constCount;
- public Constant constants;
- public Style[] styles;
- public int appendConstant() {
- return ++constCount;
- }
- public void setAppended(string field, string value) {
- constants[constCount, field] = value;
- constants[constCount, field] = value;
- }
- public void getConstant(int i){ //dummy, only for console out
- Console.WriteLine("<Constant out>");
- Console.WriteLine(" " + constants[i, "name"]);
- Console.WriteLine(" " + constants[i, "val"]);
- }
- public StyleFile()
- {
- styleCount=-1;
- constCount=-1;
- constants = new Constant(10);
- styles = new Style[5];
- }
- }
- class Class1
- {
- static void Main(string[] args)
- {
- //XmlTextReader reader = new XmlTextReader("Fonts\\FontStyles.Sc2Style");
- XmlTextReader reader = new XmlTextReader("Fonts\\test.xml");
- StyleFile f = new StyleFile();
- while (reader.Read())
- {
- if(reader.NodeType == XmlNodeType.Element){
- if (reader.Name == "Constant"){ //If element is a Constant
- Console.WriteLine("<" + reader.Name + ">");
- f.appendConstant();
- reader.MoveToFirstAttribute();
- for (int i = 1; i <= reader.AttributeCount; i++){
- Console.WriteLine(" " + reader.Name + "=" + reader.Value); //only for console out
- f.setAppended(reader.Name, reader.Value);
- reader.MoveToNextAttribute();
- }
- Console.WriteLine(" ");
- }
- else if (reader.Name == "Style") { //if element is a Style
- Console.WriteLine("<" + reader.Name + ">");
- reader.MoveToFirstAttribute();
- for (int i = 1; i <= reader.AttributeCount; i++){ //Only console out for the time being
- Console.WriteLine(" " + reader.Name + "=" + reader.Value);
- //f.setAppended(reader.Name, reader.Value);
- reader.MoveToNextAttribute();
- }
- } //disregard other element types
- }
- }
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- Console.WriteLine(" ");
- f.getConstant(0);
- f.getConstant(1);
- Console.ReadLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement