Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Xml;
- namespace StructureWriter
- {
- sealed class XMLConverter
- {
- private ArrayList Structure;
- private readonly string Header;
- private readonly int ObjectCounter;
- private readonly int LoopCounter;
- internal XMLConverter(int ObjectCounter, int LoopCounter, string Header, ArrayList Structure)
- {
- this.ObjectCounter = ObjectCounter;
- this.LoopCounter = LoopCounter;
- this.Structure = Structure;
- this.Header = Header;
- CreateXMLFile();
- }
- internal void CreateXMLFile()
- {
- using (XmlWriter writer = XmlWriter.Create("" + Header + "_structure_" + Program.Release + ".xml"))
- {
- writer.WriteStartDocument();
- writer.WriteStartElement("Facts");
- writer.WriteStartElement("Fact");
- writer.WriteAttributeString("id", "release");
- writer.WriteString(Program.Release);
- writer.WriteEndElement();
- writer.WriteStartElement("Fact");
- writer.WriteAttributeString("id", "packet header");
- writer.WriteString(Header);
- writer.WriteEndElement();
- foreach (string Struct in Structure)
- {
- writer.WriteStartElement("Structure");
- writer.WriteAttributeString("type", !Struct.Contains("OBJ") && !Struct.Contains("loop") ? ConvertCharToString(Struct) : Struct);
- writer.WriteString(!Struct.Contains("OBJ") && !Struct.Contains("loop") ? ConvertCharToString(Struct) : Struct);
- writer.WriteEndElement();
- }
- writer.WriteEndElement();
- writer.WriteEndDocument();
- }
- }
- internal string ConvertCharToString(string nChar)
- {
- if (nChar == "S")
- return "String";
- else if (nChar == "I")
- return "Integer";
- else if (nChar == "B")
- return "Boolean";
- else if (nChar == "F")
- return "Float";
- else if (nChar == "SH")
- return "Short";
- else if (nChar == "BYTE")
- return "Byte";
- else
- return "Undefined";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement