All pastes #839900 Raw Edit

XML in C#

public text v1 · immutable
#839900 ·published 2007-12-31 09:25 UTC
rendered paste body
        public void xml_write(string iName, string iSerial)
        {
            //Define everything
            XmlElement xmlelem;
            XmlElement xmlelem2;
            XmlElement xmlelem3;
            XmlText xmltext;
            string myPath = Application.StartupPath.ToString();
            //Begin Magic Special Sauce!
            XmlDocument xmldoc = new XmlDocument();
            XmlNode Declaration = xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
            xmldoc.AppendChild(Declaration);
            xmlelem = xmldoc.CreateElement("", "Xcelor8", "");
            xmldoc.AppendChild(xmlelem);

            xmlelem2 = xmldoc.CreateElement("", "Name", "");
            xmltext = xmldoc.CreateTextNode(iName);
            xmlelem2.AppendChild(xmltext);
            xmldoc.ChildNodes.Item(1).AppendChild(xmlelem2);

            xmlelem3 = xmldoc.CreateElement("", "Serial", "");
            xmltext = xmldoc.CreateTextNode(iSerial);
            xmlelem3.AppendChild(xmltext);
            xmldoc.ChildNodes.Item(1).AppendChild(xmlelem3);
            //End Magic Special Sauce

            xmldoc.Save(myPath + "\\config.xml");
        }

        public string xml_readName()
        {
            string myPath = Application.StartupPath.ToString();
            XmlDocument xmldoc = new XmlDocument();
            XmlNodeList myName;
            xmldoc.Load(myPath + "\\config.xml");
            myName = xmldoc.GetElementsByTagName("Name");
            string myNameText = myName.Item(0).InnerText;
            return myNameText;
        }
        public string xml_readSerial()
        {
            string myPath = Application.StartupPath.ToString();
            XmlDocument xmldoc = new XmlDocument();
            XmlNodeList mySerial;
            xmldoc.Load(myPath + "\\config.xml");
            mySerial = xmldoc.GetElementsByTagName("Serial");
            string mySerialText = mySerial.Item(0).InnerText;
            return mySerialText;
        }