Example #1
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);
        }
Example #2
0
 public XMLFile(XMLPrologue prologue, XMLTag root)
 {
     Prologue = prologue;
     Root     = root;
 }
Example #3
0
        private static bool GetXMLProlog(String stream, out XMLPrologue prolog, out String StreamLeft)
        {
            bool success = false;

            prolog = new XMLPrologue();
            Int32  index       = 0;
            string buffer      = "";
            int    bufferState = 0;//0 = nothing, 1 = prologue, 2 = successful getting prologue ended

            //Get inner content of prologueTag
            for (index = 0; index < stream.Length; index++)
            {
                if (bufferState == 0 && stream[index] == '<')
                {
                    if (index + 1 < stream.Length)
                    {
                        if (stream[index + 1] == '?')
                        {
                            index      += 1;
                            bufferState = 1;
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                else if (bufferState == 1)
                {
                    if (stream[index] == '?')
                    {
                        if (index + 1 < stream.Length)
                        {
                            if (stream[index + 1] == '>')
                            {
                                index      += 2;
                                bufferState = 2;
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    buffer += stream[index];
                }
            }
            //if got prologue
            if (bufferState == 2)
            {
                string   content = buffer.Trim(' ');
                string[] atts    = content.Split(' ');
                if (atts[0] == "xml")
                {
                    XMLPrologue prologue = new XMLPrologue();
                    success = true;
                    for (int i = 1; i < atts.Length; i++)
                    {
                        if (!string.IsNullOrEmpty(atts[i].Trim(' ')))
                        {
                            string   att         = atts[i].Trim(' ');
                            string[] keyAndValue = atts[i].Split('=');
                            if (keyAndValue.Length != 2)
                            {
                                success = false; break;
                            }
                            if (string.IsNullOrEmpty(keyAndValue[0]) || string.IsNullOrEmpty(keyAndValue[1]))
                            {
                                success = false; break;
                            }
                            prologue.SetAttribute(new XMLAttribute(keyAndValue[0], keyAndValue[1].Trim('\"')));
                            success = true;
                        }
                    }
                    if (success && prologue.CheckValid())
                    {
                        prolog = prologue;
                    }
                }
            }



            if (index + 1 < stream.Length)
            {
                StreamLeft = stream.Substring(index);
            }
            else
            {
                StreamLeft = "";
            }

            return(success);
        }