DOM方式讀取XML檔案(C#)

來源:互聯網
上載者:User

1。XMLFile.xml:
<?xml version="1.0" encoding="utf-8" ?>
<Resource>
  <Add Key="area_house" Value ="基地情況表(住宅及居民)"/>
  <Add Key="asset" Value ="固定資產狀況表"/>
  <Add Key="cost" Value ="成本費用情況表"/>
  <Add Key="energy_supply" Value ="基地情況表(能源供應)"/>
  <Add Key="facilities" Value ="基地情況表(服務設施表)"/>
  <Add Key="housing_service" Value ="房屋維修基金情況表"/>
  <Add Key="income" Value ="收入情況表"/>
  <Add Key="interior_charge" Value ="內部各業務互供服務收費情況表"/>
  <Add Key="investment" Value ="礦區建設投資情況表"/>
  <Add Key="organizations" Value ="組織機構情況表"/>
  <Add Key="price" Value ="價格表"/>
  <Add Key="profit" Value ="內部利潤表"/>
  <Add Key="square" Value ="基地情況表(佔地及位置)"/>
  <Add Key="workload" Value ="基地情況表(實物工作量)"/>
  <Add Key="employee" Value ="人員基本情況表"/>
</Resource>

2。C#:
XmlDocument doc = new XmlDocument();
        doc.Load(Server.MapPath("XMLFile.xml"));

        //取得你要的Resouce node的子節點
        XmlNodeList nodes = doc.SelectSingleNode("Resource").ChildNodes;

        //讀取
        foreach (XmlNode node in nodes) {

            Response.Write("Key:" + node.Attributes["Key"].Value + ",Value:" + node.Attributes["Value"].Value + "<br>");

        }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.