private XmlAttribute LoadAttributeNode()
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Attribute);

            XmlReader r = reader;

            XmlAttribute attr = dummyDocument.CreateAttribute(r.Prefix, r.LocalName, r.NamespaceURI);

            while (r.ReadAttributeValue())
            {
                switch (r.NodeType)
                {
                case XmlNodeType.Text:
                    attr.AppendChild(dummyDocument.CreateTextNode(r.Value));
                    continue;

                case XmlNodeType.EntityReference:
                    attr.AppendChild(LoadEntityReferenceInAttribute());
                    continue;

                default:
                    throw XmlLoader.UnexpectedNodeType(r.NodeType);
                }
            }

            return(attr);
        }
        private void WritePossiblyTopLevelNode(XmlNode n, bool possiblyAttribute)
        {
            CheckState();
            if (!possiblyAttribute && attribute != null)
            {
                throw new InvalidOperationException(String.Format("Current state is not acceptable for {0}.", n.NodeType));
            }

            if (state != XmlNodeType.Element)
            {
                Document.AppendChild(n);
            }
            else if (attribute != null)
            {
                attribute.AppendChild(n);
            }
            else
            {
                current.AppendChild(n);
            }
            if (state == XmlNodeType.None)
            {
                state = XmlNodeType.XmlDeclaration;
            }
        }
Beispiel #3
0
        private XmlAttribute LoadAttributeNode()
        {
            XmlReader    reader    = this.reader;
            XmlAttribute attribute = this.dummyDocument.CreateAttribute(reader.Prefix, reader.LocalName, reader.NamespaceURI);

            while (reader.ReadAttributeValue())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Text:
                {
                    attribute.AppendChild(this.dummyDocument.CreateTextNode(reader.Value));
                    continue;
                }

                case XmlNodeType.EntityReference:
                {
                    attribute.AppendChild(this.LoadEntityReferenceInAttribute());
                    continue;
                }
                }
                throw XmlLoader.UnexpectedNodeType(reader.NodeType);
            }
            return(attribute);
        }
Beispiel #4
0
 public override void WriteEntityRef(string entname)
 {
     if (state != WriteState.Attribute)
     {
         throw new InvalidOperationException("Current state is not inside attribute. Cannot write attribute value.");
     }
     attribute.AppendChild(attribute.OwnerDocument.CreateEntityReference(entname));
 }
Beispiel #5
0
        private void CreateXML()
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(fXML);
            XmlElement root = doc.DocumentElement;

            root.RemoveAll();

            foreach (Car car in list)
            {
                XmlElement   x = doc.DocumentElement;
                XmlElement   c = doc.CreateElement("brand");
                XmlAttribute a = doc.CreateAttribute("Brand");
                XmlText      t = doc.CreateTextNode(car.brand);

                XmlElement s = doc.CreateElement("car");


                XmlAttribute b = doc.CreateAttribute("color");
                XmlText      y = doc.CreateTextNode(car.color);
                b.AppendChild(y);
                s.Attributes.Append(b);

                b = doc.CreateAttribute("price");
                y = doc.CreateTextNode(car.price);
                b.AppendChild(y);
                s.Attributes.Append(b);

                b = doc.CreateAttribute("volume");
                y = doc.CreateTextNode(car.volume);
                b.AppendChild(y);
                s.Attributes.Append(b);

                b = doc.CreateAttribute("year");
                y = doc.CreateTextNode(car.year);
                b.AppendChild(y);
                s.Attributes.Append(b);

                b = doc.CreateAttribute("model");
                y = doc.CreateTextNode(car.model);
                b.AppendChild(y);
                s.Attributes.Append(b);

                c.AppendChild(s);

                a.AppendChild(t);
                c.Attributes.Append(a);
                x.AppendChild(c);
            }
            doc.Save(fXML);
        }
Beispiel #6
0
        private static XmlElement CreateSVGRoot(XmlDocument document)
        {
            XmlElement   root      = document.CreateElement("svg");
            XmlAttribute attribute = document.CreateAttribute("version");
            XmlText      xText     = document.CreateTextNode("1.1");

            attribute.AppendChild(xText);
            root.Attributes.Append(attribute);
            attribute = document.CreateAttribute("baseProfile");
            xText     = document.CreateTextNode("full");
            attribute.AppendChild(xText);
            root.Attributes.Append(attribute);

            return(root);
        }
        void IContentHandler.StartElement(string uri, string localName, string qName, IAttributes atts)
        {
            XmlQualifiedName q = new XmlQualifiedName(localName, uri);

            XmlElement elem = m_factory.GetElement(Prefix(qName), q, m_doc);

            for (int i = 0; i < atts.Length; i++)
            {
                XmlAttribute a = m_doc.CreateAttribute(Prefix(atts.GetQName(i)),
                                                       atts.GetLocalName(i),
                                                       atts.GetUri(i));
                a.AppendChild(m_doc.CreateTextNode(atts.GetValue(i)));
                elem.SetAttributeNode(a);
            }

            if ((elem.LocalName != "stream") || (elem.NamespaceURI != URI.STREAM))
            {
                if (m_stanza != null)
                {
                    m_stanza.AppendChild(elem);
                }
                m_stanza = elem;
            }
            else
            {
                FireOnDocumentStart(elem);
            }
        }
Beispiel #8
0
        public static void ArticlToXML(string head, DateTime date, Articles_Type typeArt, string text)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("XMLFileForArticle.xml");
            XmlElement xRoot = xDoc.DocumentElement;
            // создаем новый элемент user
            XmlElement cpuArt = xDoc.CreateElement("artilce");
            // создаем атрибут name
            XmlAttribute datePublication = xDoc.CreateAttribute("date");
            XmlAttribute nameArt         = xDoc.CreateAttribute("name");
            XmlAttribute artType         = xDoc.CreateAttribute("article_type");
            XmlAttribute textT           = xDoc.CreateAttribute("text");
            // создаем текстовые значения для элементов и атрибута
            XmlText textDate    = xDoc.CreateTextNode(Convert.ToString(date));
            XmlText nameofArt   = xDoc.CreateTextNode(head);
            XmlText textArtType = xDoc.CreateTextNode(Convert.ToString(typeArt));
            XmlText textText    = xDoc.CreateTextNode(Convert.ToString(text));

            //добавляем узлы
            datePublication.AppendChild(textDate);
            artType.AppendChild(textArtType);
            textT.AppendChild(textText);
            nameArt.AppendChild(nameofArt);
            cpuArt.Attributes.Append(datePublication);
            cpuArt.Attributes.Append(nameArt);
            cpuArt.Attributes.Append(artType);
            cpuArt.Attributes.Append(textT);
            xRoot.AppendChild(cpuArt);
            xDoc.Save("XMLFileForArticle.xml");
        }
Beispiel #9
0
        public void AddNewUser(User user)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("Document.xml");
            XmlElement xRoot = xDoc.DocumentElement;
            // создаем новый элемент user
            XmlElement userElem = xDoc.CreateElement("user");
            // создаем атрибут username
            XmlAttribute nameAttr = xDoc.CreateAttribute("username");
            // создаем элементы password и email
            XmlElement companyElem = xDoc.CreateElement("password");
            XmlElement ageElem     = xDoc.CreateElement("email");
            // создаем текстовые значения для элементов и атрибута
            XmlText nameText    = xDoc.CreateTextNode(user.Username);
            XmlText companyText = xDoc.CreateTextNode(user.Password);
            XmlText ageText     = xDoc.CreateTextNode(user.Email);

            //добавляем узлы
            nameAttr.AppendChild(nameText);
            companyElem.AppendChild(companyText);
            ageElem.AppendChild(ageText);
            userElem.Attributes.Append(nameAttr);
            userElem.AppendChild(companyElem);
            userElem.AppendChild(ageElem);
            xRoot.AppendChild(userElem);
            xDoc.Save("Document.xml");
        }
Beispiel #10
0
        private void addToXml()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filename);
            XmlElement   xmlRoot    = xmlDoc.DocumentElement;
            XmlElement   playerElem = xmlDoc.CreateElement("player");
            XmlAttribute idAttr     = xmlDoc.CreateAttribute("id");
            XmlElement   nameElem   = xmlDoc.CreateElement("name");
            XmlElement   scoreElem  = xmlDoc.CreateElement("score");
            XmlElement   timeElem   = xmlDoc.CreateElement("time");
            XmlText      idText     = xmlDoc.CreateTextNode((xmlRoot.ChildNodes.Count + 1).ToString());
            XmlText      nameText   = xmlDoc.CreateTextNode(txtName.Text);
            XmlText      scoreText  = xmlDoc.CreateTextNode(txtScore.Text);
            XmlText      timeText   = xmlDoc.CreateTextNode("10");

            idAttr.AppendChild(idText);
            nameElem.AppendChild(nameText);
            scoreElem.AppendChild(scoreText);
            timeElem.AppendChild(timeText);
            playerElem.Attributes.Append(idAttr);
            playerElem.AppendChild(nameElem);
            playerElem.AppendChild(scoreElem);
            playerElem.AppendChild(timeElem);
            xmlRoot.AppendChild(playerElem);
            xmlDoc.Save(filename);
            string id    = (xmlRoot.ChildNodes.Count + 1).ToString();
            string name  = txtName.Text;
            string score = txtScore.Text;
            string time  = "10";

            addPlayerToList(id, name, score, time);
        }
Beispiel #11
0
        private void subjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string      name          = "";
            string      cpw           = "";
            SubjectForm teacherDialog = new SubjectForm();

            if (teacherDialog.ShowDialog(this) == DialogResult.OK)
            {
                cpw  = teacherDialog.textBox2.Text;
                name = teacherDialog.textBox1.Text;
            }
            else
            {
                return;
            }

            XmlElement   teacherElement = doc.CreateElement("subject");
            XmlAttribute teachersName   = doc.CreateAttribute("name");
            XmlText      nameText       = doc.CreateTextNode(name);

            teachersName.AppendChild(nameText);
            teacherElement.Attributes.Append(teachersName);

            XmlAttribute sujcectsCpw = doc.CreateAttribute("cpw");
            XmlText      cpwText     = doc.CreateTextNode(cpw);

            sujcectsCpw.AppendChild(cpwText);
            teacherElement.Attributes.Append(sujcectsCpw);
            xRoot.AppendChild(teacherElement);
            dataGridView1.Rows.Add(name, cpw);
        }
Beispiel #12
0
        public static string Create(int roleId, string[] componentTypeIds, string[] sequenceIds, string[] permissionMasks)
        {
            XmlDocument  xDoc       = new XmlDocument();
            XmlNode      root       = xDoc.CreateElement("ROLEPERMISSIONS");
            XmlNode      roleItem   = xDoc.CreateElement("ROLE");
            XmlAttribute role_Id    = xDoc.CreateAttribute("ID");
            XmlNode      permission = xDoc.CreateElement("PERMISSION");

            role_Id.AppendChild(xDoc.CreateTextNode(roleId.ToString()));

            for (int idx = 0; idx < componentTypeIds.Length - 1; idx++)
            {
                XmlAttribute compType = xDoc.CreateAttribute("COMPTYPEID");
                compType.AppendChild(xDoc.CreateTextNode(componentTypeIds[idx]));

                XmlAttribute sequenceId = xDoc.CreateAttribute("SEQNO");
                sequenceId.AppendChild(xDoc.CreateTextNode(sequenceIds[idx]));

                XmlAttribute permissionMask = xDoc.CreateAttribute("PMASK");
                permissionMask.AppendChild(xDoc.CreateTextNode(permissionMasks[idx]));

                permission.AppendChild(permissionMask);
                permission.AppendChild(sequenceId);
                permission.AppendChild(compType);
            }

            roleItem.AppendChild(permission);
            roleItem.AppendChild(role_Id);
            root.AppendChild(roleItem);

            return(root.OuterXml);
        }
Beispiel #13
0
        public void take()
        {
            XmlDocument Doc = new XmlDocument();

            Doc.Load("card.xml");
            XmlElement  cRoot  = Doc.DocumentElement;
            XmlNodeList cNodes = cRoot.SelectNodes("card");
            XmlNode     k      = cRoot.FirstChild;
            bool        f      = false;

            foreach (XmlNode n in cNodes)
            {
                if (n.SelectSingleNode("@fio").Value == this.people)
                {
                    f = true;
                    k = n;
                }
            }
            if (f)
            {
                XmlElement   booksElem = Doc.CreateElement("book");
                XmlAttribute nameAttr  = Doc.CreateAttribute("name");
                XmlElement   handElem  = Doc.CreateElement("hand");
                // создаем текстовые значения для элементов и атрибута
                XmlText booksText = Doc.CreateTextNode(this.books);
                XmlText handText  = Doc.CreateTextNode(this.hand);
                //добавляем узлы
                nameAttr.AppendChild(booksText);
                handElem.AppendChild(handText);
                booksElem.Attributes.Append(nameAttr);
                booksElem.AppendChild(handElem);
                k.AppendChild(booksElem);
                cRoot.AppendChild(k);
                Doc.Save("card.xml");
            }
            else
            {
                XmlElement cElem = Doc.CreateElement("card");
                // создаем атрибут name
                XmlAttribute peopleAttr = Doc.CreateAttribute("fio");
                // создаем элементы
                XmlElement   booksElem = Doc.CreateElement("book");
                XmlAttribute nameAttr  = Doc.CreateAttribute("name");
                XmlElement   handElem  = Doc.CreateElement("hand");
                // создаем текстовые значения для элементов и атрибута
                XmlText peopleText = Doc.CreateTextNode(this.people);
                XmlText booksText  = Doc.CreateTextNode(this.books);
                XmlText handText   = Doc.CreateTextNode(this.hand);
                //добавляем узлы
                peopleAttr.AppendChild(peopleText);
                nameAttr.AppendChild(booksText);
                handElem.AppendChild(handText);
                cElem.Attributes.Append(peopleAttr);
                booksElem.Attributes.Append(nameAttr);
                booksElem.AppendChild(handElem);
                cElem.AppendChild(booksElem);
                cRoot.AppendChild(cElem);
                Doc.Save("card.xml");
            }
        }
        private void SaveTempData()
        {
            string TableItemName = FullTileName;

            Utility.isExists("temp/tableData" + TableID + ".xml", Utility.ExistsType.XML);

            XmlDocument xTempDoc = new XmlDocument();

            xTempDoc.Load("temp/tableData" + TableID + ".xml");
            XmlElement xTempRoot = xTempDoc.DocumentElement;

            XmlElement tableTempElem      = xTempDoc.CreateElement(TableItemName);
            XmlElement oCountTempElem     = xTempDoc.CreateElement("OrdersCount");
            XmlText    oCountTempElemText = xTempDoc.CreateTextNode(MarkedOrderList.Items.Count.ToString());

            tableTempElem = xTempDoc.CreateElement(TableItemName);

            for (int i = 0; i < MarkedOrderList.Items.Count; i++)
            {
                XmlAttribute priceAttr      = xTempDoc.CreateAttribute("price");
                XmlElement   xOrderTempName = xTempDoc.CreateElement(MarkedOrderList.Items[i].ToString());
                XmlText      xOrderTempText = xTempDoc.CreateTextNode(MarkedOrderList.Items[i].ToString());
                xOrderTempName.AppendChild(xOrderTempText);
                XmlText priceVal = xTempDoc.CreateTextNode(OrdersCostArray[i].ToString());
                priceAttr.AppendChild(priceVal);
                xOrderTempName.Attributes.Append(priceAttr);
                tableTempElem.AppendChild(xOrderTempName);
            }
            oCountTempElem.AppendChild(oCountTempElemText);
            xTempRoot.AppendChild(tableTempElem);
            xTempRoot.AppendChild(oCountTempElem);
            xTempDoc.Save("temp/tableData" + TableID + ".xml");
        }
Beispiel #15
0
        void SaveNewProductToXml(Product newProduct)                                                //Метод сохранени нового продукта в xml файле
        {
            XmlDocument xmlProductList = new XmlDocument();                                         //Создали новый экземпляр xml документа

            xmlProductList.Load(xmlProductListPath);                                                //Загрузили xml документ
            XmlElement xmlProdListElement = xmlProductList.DocumentElement;                         //Получил корень документа

            XmlElement   productElement          = xmlProductList.CreateElement("product");         //В корне создал элемент product
            XmlAttribute productNameAttribute    = xmlProductList.CreateAttribute("name");          //Для элемента product создал атрибут name
            XmlElement   productCountTypeElement = xmlProductList.CreateElement("countType");       //В элементе product создал элемент countType
            XmlElement   productMassElement      = xmlProductList.CreateElement("mass");            //В элементе product создал элемент mass
            XmlElement   productPriceElement     = xmlProductList.CreateElement("price");           //В элементе product создал элемент price
            XmlElement   productSumElement       = xmlProductList.CreateElement("sum");             //В элементе product создал элемент sum

            XmlText productNameText      = xmlProductList.CreateTextNode(newProduct.prodName);      //Создал текст для помещения в элемент
            XmlText productCountTypeText = xmlProductList.CreateTextNode(newProduct.prodCountType); //Создал текст для помещения в элемент
            XmlText productMassText      = xmlProductList.CreateTextNode(newProduct.prodMass);      //Создал текст для помещения в элемент
            XmlText productPriceText     = xmlProductList.CreateTextNode(newProduct.prodPrice);     //Создал текст для помещения в элемент
            XmlText productSumText       = xmlProductList.CreateTextNode(newProduct.prodSum);       //Создал текст для помещения в элемент

            productNameAttribute.AppendChild(productNameText);                                      //Поместил текст в атрибут элемента
            productCountTypeElement.AppendChild(productCountTypeText);                              //Поместил текст в элемент
            productMassElement.AppendChild(productMassText);                                        //Поместил текст в элемент
            productPriceElement.AppendChild(productPriceText);                                      //Поместил текст в элемент
            productSumElement.AppendChild(productSumText);                                          //Поместил текст в элемент

            productElement.Attributes.Append(productNameAttribute);                                 //Добавил атрибут name элементу product
            productElement.AppendChild(productCountTypeElement);                                    //Добавил элемент countType в элемент product
            productElement.AppendChild(productMassElement);                                         //Добавил элемент mass в элемент product
            productElement.AppendChild(productPriceElement);
            productElement.AppendChild(productSumElement);

            xmlProdListElement.AppendChild(productElement); //Поместил всё в xml
            xmlProductList.Save(xmlProductListPath);        //Save xml to local folder
        }
Beispiel #16
0
        public void UndoAttributeChange()
        {
            XmlElement elem = doc.CreateElement("test");

            doc.DocumentElement.AppendChild(elem);
            XmlText      t = doc.CreateTextNode("testval");
            XmlAttribute a = doc.CreateAttribute("testatt");

            a.AppendChild(t);

            u = new UndoManager(null);
            u.Attach(doc);

            elem.SetAttributeNode(a);

            u.Mark(null);

            Assert.AreEqual("testval", elem.GetAttribute("testatt"), "Wrong initial value for attribute");

            t.Value = "testval2";
//			elem.SetAttribute("testatt", "testval2");
            Assert.AreEqual("testval2", elem.GetAttribute("testatt"), "Wrong modified value for attribute");

            u.Undo(null);
            Assert.AreEqual("testval", elem.GetAttribute("testatt"), "Wrong value for attribute after undo");
        }
Beispiel #17
0
        private void AddWords()
        {
            XmlElement words = _configuration.CreateElement("words");

            _configuration.DocumentElement.AppendChild(words);
            foreach (Control item in Controls)
            {
                if (item is TextBox)
                {
                    XmlElement word = _configuration.CreateElement("word");

                    XmlAttribute name = _configuration.CreateAttribute("name");
                    name.AppendChild(_configuration.CreateTextNode((item as TextBox).Text));
                    word.Attributes.Append(name);

                    words.AppendChild(word);
                }

                if (item is RichTextBox)
                {
                    XmlNode word = words.LastChild;

                    XmlElement definition = _configuration.CreateElement("definition");
                    definition.AppendChild(_configuration.CreateTextNode((item as RichTextBox).Text));

                    word.AppendChild(definition);
                }
            }
            _configuration.Save(_configPath);
        }
Beispiel #18
0
        public void Create(Cat item)
        {
            document.Load(fileName);
            XmlElement xRoot = document.DocumentElement;
            // создаем новый элемент cat
            XmlElement catElem = document.CreateElement("cat");
            // создаем атрибут id
            XmlAttribute idAttr = document.CreateAttribute("id");
            // создаем элементы name и weight
            XmlElement nameElem   = document.CreateElement("name");
            XmlElement weightElem = document.CreateElement("weight");
            // создаем текстовые значения для элементов и атрибута
            XmlText id         = document.CreateTextNode(item.Id.ToString());
            XmlText nameText   = document.CreateTextNode(item.Name);
            XmlText weightText = document.CreateTextNode(item.Weight.ToString());

            //добавляем узлы
            idAttr.AppendChild(id);
            nameElem.AppendChild(nameText);
            weightElem.AppendChild(weightText);
            catElem.Attributes.Append(idAttr);
            catElem.AppendChild(nameElem);
            catElem.AppendChild(weightElem);
            xRoot.AppendChild(catElem);
            document.Save(fileName);
        }
Beispiel #19
0
        public void saveToFile()
        {
            XmlElement   xRoot      = xDoc.DocumentElement;
            XmlElement   workerElem = xDoc.CreateElement("worker");
            XmlAttribute nameAttr   = xDoc.CreateAttribute("second_name");
            XmlElement   salElem    = xDoc.CreateElement("salary");
            XmlElement   postElem   = xDoc.CreateElement("post");
            XmlElement   cityElem   = xDoc.CreateElement("city");
            XmlElement   strElem    = xDoc.CreateElement("street");
            XmlElement   houseElem  = xDoc.CreateElement("house");

            nameAttr.AppendChild(xDoc.CreateTextNode(workerView.worker.SecName));
            salElem.AppendChild(xDoc.CreateTextNode(workerView.worker.Salary.ToString()));
            postElem.AppendChild(xDoc.CreateTextNode(workerView.Post));
            cityElem.AppendChild(xDoc.CreateTextNode(workerView.City));
            strElem.AppendChild(xDoc.CreateTextNode(workerView.Street));
            houseElem.AppendChild(xDoc.CreateTextNode(workerView.worker.House.ToString()));

            workerElem.Attributes.Append(nameAttr);
            workerElem.AppendChild(salElem);
            workerElem.AppendChild(postElem);
            workerElem.AppendChild(cityElem);
            workerElem.AppendChild(strElem);
            workerElem.AppendChild(houseElem);
            xRoot.AppendChild(workerElem);
            xDoc.Save(path);
        }
Beispiel #20
0
        private void AddToConfig(decimal x, decimal y, decimal len, object pos)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(config);

            XmlElement wc = doc.CreateElement("wConf");

            XmlAttribute xXml = doc.CreateAttribute("x");

            xXml.AppendChild(doc.CreateTextNode(x.ToString()));

            XmlAttribute yXml = doc.CreateAttribute("y");

            yXml.AppendChild(doc.CreateTextNode(y.ToString()));

            XmlAttribute lengthXml = doc.CreateAttribute("length");

            lengthXml.AppendChild(doc.CreateTextNode(len.ToString()));

            XmlAttribute positionXml = doc.CreateAttribute("position");

            positionXml.AppendChild(doc.CreateTextNode(pos.ToString()));

            wc.Attributes.Append(xXml);
            wc.Attributes.Append(yXml);
            wc.Attributes.Append(lengthXml);
            wc.Attributes.Append(positionXml);

            doc.ChildNodes.Item(0).ChildNodes.Item(0).AppendChild(wc);
            doc.Save(config);
        }
Beispiel #21
0
        private static void AddElement()
        {
            XmlDocument document = new XmlDocument();

            document.Load("XMLFile.xml");

            XmlElement   root          = document.DocumentElement;
            XmlElement   user          = document.CreateElement("user");
            XmlAttribute attributeName = document.CreateAttribute("name");
            XmlElement   company       = document.CreateElement("company");
            XmlElement   age           = document.CreateElement("age");

            XmlText nameText    = document.CreateTextNode("Марк Цукерберг");
            XmlText companyText = document.CreateTextNode("The Facebook");
            XmlText ageText     = document.CreateTextNode("25");

            attributeName.AppendChild(nameText);
            company.AppendChild(companyText);
            age.AppendChild(ageText);

            user.Attributes.Append(attributeName);
            user.AppendChild(company);
            user.AppendChild(age);

            root.AppendChild(user);
            document.Save("XMLFile.xml");
        }
Beispiel #22
0
        private void button1_Click(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load("EmployeeList.xml");
            XmlElement   root       = doc.DocumentElement;
            XmlElement   employee   = doc.CreateElement("Employee");
            XmlAttribute id         = doc.CreateAttribute("ID");
            XmlElement   name       = doc.CreateElement("Name");
            XmlElement   post       = doc.CreateElement("Post");
            XmlElement   salary     = doc.CreateElement("Salary");
            XmlText      idText     = doc.CreateTextNode(textBox4.Text);
            XmlText      nameText   = doc.CreateTextNode(textBox1.Text);
            XmlText      postText   = doc.CreateTextNode(textBox2.Text);
            XmlText      salaryText = doc.CreateTextNode(textBox3.Text);


            id.AppendChild(idText);
            name.AppendChild(nameText);
            post.AppendChild(postText);
            salary.AppendChild(salaryText);
            employee.Attributes.Append(id);
            employee.AppendChild(name);
            employee.AppendChild(post);
            employee.AppendChild(salary);
            root.AppendChild(employee);
            doc.Save("EmployeeList.xml");
            textBox1.Text = String.Empty;
            textBox2.Text = String.Empty;
            textBox3.Text = String.Empty;
            textBox4.Text = String.Empty;
        }
        internal void AppendToXml(FootballClub newClub)
        {
            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("clubs.xml");
            XmlElement xRoot = xDoc.DocumentElement;

            XmlElement   clubElem      = xDoc.CreateElement("club");
            XmlAttribute idAttr        = xDoc.CreateAttribute("id");
            XmlElement   nameElem      = xDoc.CreateElement("name");
            XmlElement   imagePathElem = xDoc.CreateElement("imagePath");

            XmlText idText        = xDoc.CreateTextNode(newClub.Id.ToString());
            XmlText nameText      = xDoc.CreateTextNode(newClub.Name);
            XmlText imagePathText = xDoc.CreateTextNode(newClub.ImagePath);

            idAttr.AppendChild(idText);
            nameElem.AppendChild(nameText);
            imagePathElem.AppendChild(imagePathText);
            clubElem.Attributes.Append(idAttr);
            clubElem.AppendChild(nameElem);
            clubElem.AppendChild(imagePathElem);

            xRoot.AppendChild(clubElem);
            xDoc.Save("clubs.xml");
        }
Beispiel #24
0
        public void Create(Student item)
        {
            XmlElement xRoot = xDoc.DocumentElement;

            XmlElement   studentElem   = xDoc.CreateElement(StringsResources.Student);
            XmlAttribute studentIDAttr = xDoc.CreateAttribute(StringsResources.StudentID);

            XmlElement studentFirstNameElem = xDoc.CreateElement(StringsResources.StudentFirstName);
            XmlElement studentLastNameElem  = xDoc.CreateElement(StringsResources.StudentLastName);
            XmlElement studentAgeElem       = xDoc.CreateElement(StringsResources.StudentAge);
            XmlElement studentGenderElem    = xDoc.CreateElement(StringsResources.StudentGender);

            XmlText idText        = xDoc.CreateTextNode((++lastID).ToString());
            XmlText firstNameText = xDoc.CreateTextNode(item.FirstName);
            XmlText lastNameText  = xDoc.CreateTextNode(item.LastName);
            XmlText ageText       = xDoc.CreateTextNode(item.Age.ToString());
            XmlText genderText    = xDoc.CreateTextNode(item.Gender.ToString());

            studentIDAttr.AppendChild(idText);
            studentFirstNameElem.AppendChild(firstNameText);
            studentLastNameElem.AppendChild(lastNameText);
            studentAgeElem.AppendChild(ageText);
            studentGenderElem.AppendChild(genderText);

            studentElem.Attributes.Append(studentIDAttr);
            studentElem.AppendChild(studentFirstNameElem);
            studentElem.AppendChild(studentLastNameElem);
            studentElem.AppendChild(studentAgeElem);
            studentElem.AppendChild(studentGenderElem);

            xRoot.AppendChild(studentElem);
        }
Beispiel #25
0
        public static void AddToDb(string p_name, string p_number, string p_allconts, string p_email, string p_address)
        {
            var xdoc = new XmlDocument();

            xdoc.Load(Declarator.PathContacsDb);
            XmlElement xRoot = xdoc.DocumentElement;

            XmlElement   contactElem     = xdoc.CreateElement("contact");
            XmlAttribute nameAttr        = xdoc.CreateAttribute("name");
            XmlText      name            = xdoc.CreateTextNode(p_name);
            XmlElement   numberElem      = xdoc.CreateElement("number");
            XmlText      number          = xdoc.CreateTextNode(p_number);
            XmlElement   allcontactsElem = xdoc.CreateElement("all_contacts");
            XmlText      allcontacts     = xdoc.CreateTextNode(p_allconts);
            XmlElement   emailElem       = xdoc.CreateElement("email");
            XmlText      email           = xdoc.CreateTextNode(p_email);
            XmlElement   addressElem     = xdoc.CreateElement("address");
            XmlText      address         = xdoc.CreateTextNode(p_address);

            nameAttr.AppendChild(name);
            numberElem.AppendChild(number);
            allcontactsElem.AppendChild(allcontacts);
            emailElem.AppendChild(email);
            addressElem.AppendChild(address);
            contactElem.Attributes.Append(nameAttr);
            contactElem.AppendChild(numberElem);
            contactElem.AppendChild(allcontactsElem);
            contactElem.AppendChild(emailElem);
            contactElem.AppendChild(addressElem);
            xRoot.AppendChild(contactElem);
            xdoc.Save(Declarator.PathContacsDb);
            xmlNodeList = xRoot.ChildNodes;
        }
Beispiel #26
0
        static void Main(string[] args)
        {
            // изменение XML-документа. Добавление элемента

            XmlDocument xDoc = new XmlDocument();

            xDoc.Load("C://Users//1//Desktop//text.xml");
            XmlElement xRoot = xDoc.DocumentElement;
            // создаем новый элемент user
            XmlElement userElem = xDoc.CreateElement("user");
            // создаем атрибут name
            XmlAttribute nameAttr = xDoc.CreateAttribute("name");
            // создаем элементы company и age
            XmlElement companyElem = xDoc.CreateElement("company");
            XmlElement ageElem     = xDoc.CreateElement("age");
            // создаем текстовые значения для элементов и атрибута
            XmlText nameText    = xDoc.CreateTextNode("Mark Zuckerberg");
            XmlText companyText = xDoc.CreateTextNode("Facebook");
            XmlText ageText     = xDoc.CreateTextNode("30");

            //добавляем узлы
            nameAttr.AppendChild(nameText);
            companyElem.AppendChild(companyText);
            ageElem.AppendChild(ageText);
            userElem.Attributes.Append(nameAttr);
            userElem.AppendChild(companyElem);
            userElem.AppendChild(ageElem);
            xRoot.AppendChild(userElem);
            xDoc.Save("C://Users//1//Desktop//text.xml");
        }
Beispiel #27
0
        private void addUrl_Click(object sender, EventArgs e)
        {
            if (url != null)
            {
                DateTime localDate = DateTime.Now;

                string data = localDate.ToString();

                XmlDocument doc = new XmlDocument();
                doc.Load(pathMark);
                XmlElement xRoot = doc.DocumentElement;

                XmlElement   siteElem = doc.CreateElement("site");
                XmlAttribute dataAttr = doc.CreateAttribute("data");
                XmlAttribute urlAttr  = doc.CreateAttribute("url");

                XmlText dataText = doc.CreateTextNode(data);
                XmlText urlText  = doc.CreateTextNode(url);

                dataAttr.AppendChild(dataText);
                urlAttr.AppendChild(urlText);

                siteElem.Attributes.Append(dataAttr);
                siteElem.Attributes.Append(urlAttr);

                xRoot.AppendChild(siteElem);
                doc.Save(pathMark);
            }
        }
Beispiel #28
0
        public void add()
        {
            XmlDocument Doc = new XmlDocument();

            Doc.Load("reader.xml");
            XmlElement rRoot = Doc.DocumentElement;
            // создаем новый элемент reader
            XmlElement rElem = Doc.CreateElement("reader");
            // создаем атрибут name
            XmlAttribute fioAttr = Doc.CreateAttribute("fio");
            // создаем элементы
            XmlElement addressElem   = Doc.CreateElement("address");
            XmlElement telephoneElem = Doc.CreateElement("telephone");
            // создаем текстовые значения для элементов и атрибута
            XmlText fioText       = Doc.CreateTextNode(this.fio);
            XmlText addressText   = Doc.CreateTextNode(this.address);
            XmlText telephoneText = Doc.CreateTextNode(this.telephone);

            //добавляем узлы
            fioAttr.AppendChild(fioText);
            addressElem.AppendChild(addressText);
            telephoneElem.AppendChild(telephoneText);
            rElem.Attributes.Append(fioAttr);
            rElem.AppendChild(addressElem);
            rElem.AppendChild(telephoneElem);
            rRoot.AppendChild(rElem);
            Doc.Save("reader.xml");
        }
Beispiel #29
0
        void browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            pages.SelectedTab.Text = ((WebBrowser)pages.SelectedTab.Controls[0]).DocumentTitle;

            url = e.Url.ToString();

            DateTime localDate = DateTime.Now;

            string data = localDate.ToString();

            XmlDocument doc = new XmlDocument();

            doc.Load(pathHistory);
            XmlElement xRoot = doc.DocumentElement;

            XmlElement   siteElem = doc.CreateElement("site");
            XmlAttribute dataAttr = doc.CreateAttribute("data");
            XmlAttribute urlAttr  = doc.CreateAttribute("url");

            XmlText dataText = doc.CreateTextNode(data);
            XmlText urlText  = doc.CreateTextNode(url);

            dataAttr.AppendChild(dataText);
            urlAttr.AppendChild(urlText);

            siteElem.Attributes.Append(dataAttr);
            siteElem.Attributes.Append(urlAttr);

            xRoot.AppendChild(siteElem);
            doc.Save(pathHistory);
        }
Beispiel #30
0
        public void ChangeCurMiner()
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filenameSetting);
            XmlElement xRoot = xmlDoc.DocumentElement;

            foreach (XmlNode xnode in xRoot)
            {
                if (xnode.Name == "current_miner")
                {
                    xRoot.RemoveChild(xnode);
                    break;
                }
            }

            XmlElement   current_minerElem     = xmlDoc.CreateElement("current_miner");
            XmlAttribute current_minerAttr     = xmlDoc.CreateAttribute("current_miner");
            XmlText      current_minerAttrName = xmlDoc.CreateTextNode(currentMiner.name);
            XmlElement   current_minerName     = xmlDoc.CreateElement("name");

            XmlText current_miner = xmlDoc.CreateTextNode(currentMiner.name);

            current_minerAttr.AppendChild(current_minerAttrName);
            current_minerName.AppendChild(current_miner);
            current_minerElem.Attributes.Append(current_minerAttr);
            current_minerElem.AppendChild(current_minerName);
            xRoot.AppendChild(current_minerElem);
            xmlDoc.Save(filenameSetting);
        }