예제 #1
0
        public static string GetXMLFileFromLines(string[] lines, out XMLFile xml)
        {
            string success = "";

            xml = new XMLFile(new XMLPrologue(), new XMLTag("Error", "Couldn't get XMLFile at GetXMLFileFromLines.", new XMLTag[0], new XMLAttribute[0]));
            String      stream = string.Join(string.Empty, lines);
            XMLPrologue prologue;
            string      StreamLeft;

            if (GetXMLProlog(stream, out prologue, out StreamLeft))
            {
                xml.Prologue = prologue;
            }
            else
            {
                StreamLeft = stream;
            }
            XMLTag[] tags;
            success = GetTags(StreamLeft, out tags);
            if (success == "")
            {
                if (tags.Length == 1)
                {
                    xml.Root = tags[0];
                }
                else
                {
                    success = "Error! XML should have one, and just one root tag!";
                }
            }
            return(success);
        }
예제 #2
0
        public static string GetXMLFile(string path, out XMLFile xml)
        {
            string success = ""; //Empty equals success, error contains error message

            String[] lines = IOManager.GetFile(path);
            return(GetXMLFileFromLines(lines, out xml));
        }
예제 #3
0
        public static void SaveXMLFile(string path, XMLFile xml)
        {
            List <string> lines = new List <string>();

            if (xml.Prologue != null)
            {
                lines.Add(xml.Prologue.ToXmlPrologueText());
            }
            lines.AddRange(xml.Root.ToXmlText());
            IOManager.WriteFile(path, lines.ToArray());
        }
예제 #4
0
        public static void SaveExample(string path)
        {
            XMLPrologue prologue = new XMLPrologue();
            XMLTag      root     = new XMLTag("Person", string.Empty);
            XMLTag      nome     = new XMLTag("Name", "João da Silva");

            nome.SetAttribute(new XMLAttribute("Compound", "Yes"));
            root.AddChild(nome);
            root.AddChild(new XMLTag("Age", "15"));
            root.AddChild(new XMLTag("Cidade", "São Paulo"));
            root.SetAttribute(new XMLAttribute("Raca", "Pardo"));
            XMLFile file = new XMLFile(prologue, root);

            XMLManager.SaveXMLFile(path, file);
        }