欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

C#操作XMl文件(2):使用XmlReader和XmlWriter實(shí)現(xiàn)讀取和寫入

這次使用操作Xml較為常用的方法:使用XMlreader和Xmlwriter

成都創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)營(yíng)銷推廣、網(wǎng)站重做改版、福綿網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、成都h5網(wǎng)站建設(shè)商城開發(fā)、集團(tuán)公司官網(wǎng)建設(shè)、成都外貿(mào)網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為福綿等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

1:讀取xml文件的數(shù)學(xué)和元素

XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreWhitespace = true;

        XmlReader reader = XmlReader.Create("Customer2.xml", settings);
        List<CustomerInfo> lists = new List<CustomerInfo>();
        CustomerInfo cust = null;

        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element)
            {
                switch (reader.Name)
                {
                    case "row":
                        cust = new CustomerInfo();
                        if (reader.HasAttributes)
                        {
                            cust.AppId = reader.GetAttribute("AppID");
                            cust.Version = reader.GetAttribute("Version");
                        }
                        break;

                    case "CustomerID":
                        cust.CustomerID = reader.ReadString();
                        break;

                    case "CompanyName":
                        cust.CompanyName = reader.ReadString();
                        break;
                    case "ContactName":

                        cust.ContactName = reader.ReadString();
                        break;
                    case "ContactTitle":

                        cust.ContactTitle = reader.ReadString();
                        break;

                    case "Address":

                        cust.Address = reader.ReadString();
                        break;

                    case "City":
                        cust.City = reader.ReadString();
                        break;

                    case "PostalCode":
                        cust.PostalCode = reader.ReadString();
                        break;
                    case "Country":
                        cust.Country = reader.ReadString();
                        break;
                    case "Phone":
                        cust.Phone = reader.ReadString();
                        break;
                    case "Fax":
                        cust.Fax = reader.ReadString();
                        lists.Add(cust);
                        break;
                    default:
                        break;

                }
            }
        }

2.創(chuàng)建文檔-屬性和元素
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = false;
XmlWriter writer = XmlWriter.Create("CustomerNewElementArribute.xml", settings);
writer.WriteStartDocument();
writer.WriteStartElement("Table");

        for (int i = 1; i < 10; i++)
        {
            writer.WriteStartElement("row");
            writer.WriteAttributeString("Version", "2.0");
            writer.WriteAttributeString("AppID", "111");
            writer.WriteElementString("CustomerID", "cmz" + i.ToString());
            writer.WriteElementString("CompanyName", "程沐喆" + i.ToString());
            writer.WriteElementString("ContactName", "Maria Anders" + i.ToString());
            writer.WriteElementString("ContactTitle", "Sales Representative" + i.ToString());
            writer.WriteElementString("Address", "Obere Str. 57" + i.ToString());
            writer.WriteElementString("City", "Berlin");
            writer.WriteElementString("PostalCode", "12209");
            writer.WriteElementString("Country", "Germany");
            writer.WriteElementString("Phone", "030-0074321");
            writer.WriteElementString("Fax", "030-0076545");
            writer.WriteEndElement();
        }

        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Flush();
        writer.Close();

    }

    private void button7_Click(object sender, EventArgs e)
    {
        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        settings.NewLineOnAttributes = false;
        settings.Encoding = Encoding.UTF8;
        StringBuilder builder = new StringBuilder();
        XmlWriter writer = XmlWriter.Create(builder, settings);
        writer.WriteStartDocument();
        writer.WriteStartElement("Table");

        for (int i = 1; i < 5; i++)
        {
            writer.WriteStartElement("row");
            writer.WriteAttributeString("Version", "2.0");
            writer.WriteAttributeString("AppID", "111");
            writer.WriteElementString("CustomerID", "cmz" + i.ToString());
            writer.WriteElementString("CompanyName", "程沐喆" + i.ToString());
            writer.WriteElementString("ContactName", "Maria Anders" + i.ToString());
            writer.WriteElementString("ContactTitle", "Sales Representative" + i.ToString());
            writer.WriteElementString("Address", "Obere Str. 57" + i.ToString());
            writer.WriteElementString("City", "Berlin");
            writer.WriteElementString("PostalCode", "12209");
            writer.WriteElementString("Country", "Germany");
            writer.WriteElementString("Phone", "030-0074321");
            writer.WriteElementString("Fax", "030-0076545");
            writer.WriteEndElement();
        }
        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Flush();
        writer.Close();

另外在介紹自己學(xué)習(xí)的使用xmlwriter寫入StringBuiler和Stream

創(chuàng)建xml寫入StringBuiler:

XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = false;
settings.Encoding = Encoding.UTF8;
StringBuilder builder = new StringBuilder();
XmlWriter writer = XmlWriter.Create(builder, settings);
writer.WriteStartDocument();
writer.WriteStartElement("Table");

        for (int i = 1; i < 5; i++)
        {
            writer.WriteStartElement("row");
            writer.WriteAttributeString("Version", "2.0");
            writer.WriteAttributeString("AppID", "111");
            writer.WriteElementString("CustomerID", "ALFKI" + i.ToString());
            writer.WriteElementString("CompanyName", "Alfreds Futterkiste" + i.ToString());
            writer.WriteElementString("ContactName", "Maria Anders" + i.ToString());
            writer.WriteElementString("ContactTitle", "Sales Representative" + i.ToString());
            writer.WriteElementString("Address", "Obere Str. 57" + i.ToString());
            writer.WriteElementString("City", "Berlin");
            writer.WriteElementString("PostalCode", "12209");
            writer.WriteElementString("Country", "Germany");
            writer.WriteElementString("Phone", "030-0074321");
            writer.WriteElementString("Fax", "030-0076545");
            writer.WriteEndElement();
        }
        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Flush();
        writer.Close();

創(chuàng)建xml寫入stream:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineOnAttributes = false;
settings.Encoding = new UTF8Encoding(false);
MemoryStream stream = new MemoryStream();
XmlWriter writer = XmlWriter.Create(stream, settings);
writer.WriteStartDocument();
writer.WriteStartElement("Table");

        for (int i = 1; i < 5; i++)
        {
            writer.WriteStartElement("row");
            writer.WriteAttributeString("Version", "2.0");
            writer.WriteAttributeString("AppID", "111");
            writer.WriteElementString("CustomerID", "ALFKI" + i.ToString());
            writer.WriteElementString("CompanyName", "Alfreds Futterkiste" + i.ToString());
            writer.WriteElementString("ContactName", "Maria Anders" + i.ToString());
            writer.WriteElementString("ContactTitle", "Sales Representative" + i.ToString());
            writer.WriteElementString("Address", "Obere Str. 57" + i.ToString());
            writer.WriteElementString("City", "Berlin");
            writer.WriteElementString("PostalCode", "12209");
            writer.WriteElementString("Country", "Germany");
            writer.WriteElementString("Phone", "030-0074321");
            writer.WriteElementString("Fax", "030-0076545");
            writer.WriteEndElement();
        }
        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Flush();
        writer.Close();

本文標(biāo)題:C#操作XMl文件(2):使用XmlReader和XmlWriter實(shí)現(xiàn)讀取和寫入
本文路徑:http://aaarwkj.com/article22/goocjc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)定制開發(fā)、網(wǎng)站改版、外貿(mào)網(wǎng)站建設(shè)、App設(shè)計(jì)、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)
av黄色天堂在线观看| 国产精品一级性生活片| 国产真实内射在线观看| 国产精品传媒免费在线观看| 精品国产视频一区二区三区| 久久中文人妻丝袜不卡| 欧美性色黄大片人与善| 欧美精品一区二区精品久久| 亚洲av少妇高潮流白浆在线| 亚洲精品在线观看日本| 日韩精品在线另类亚洲| 激情少妇一区二区三区| 亚洲一区二区精品免费视频| 日韩av一区二区国产| 四虎久久久最新网址| 欧美精品久久在线观看| 久久国产精品成人免费蜜臀| 少妇高潮一区二区三区99| 国产熟女一区二区三区正在| 色婷婷av一区二区三| 国产日韩手机在线不卡视频| 最新天堂av资源在线观看| 热99精品视频在线观看| 九九热视频在线观看色| 欧美亚洲综合另类色妞| 亚洲最大午夜福利视频| 偷窥偷拍视频一区二区| 国内午夜福利精品视频| 中文在线在线天堂中文| 巨乳人妻一区二区三区| 亚洲中文字幕av天堂久久| 欧美日韩欧美日韩一区二区| 日韩亚洲毛片全在线播放| 精品日韩欧美精品日韩| 成人黄色动作片在线观看| 少妇按摩高潮呻吟av| av天天堂网在线播放| 大胆丰满邻居少妇在线观看| 国产亚洲高清一区二区| 日本东京热二三四区不卡免费的| 国产情侣自拍视频在线观看|