zoukankan      html  css  js  c++  java
  • Linq to xml 读取xml文件或xml字符串

    XMLFile1.xml:

    XDocument Contacts = XDocument.Load("XMLFile1.xml");
    //XElement Contacts = XElement.Parse(xmldata);
    var Elist = from t in Contacts.Descendants("HEADER")
    select new
    {
    CREATION_DATE = t.Element("CREATION_DATE").Value.Replace(" ", ""),
    ITEM_NUMBER = t.Element("ITEM_NUMBER").Value.Replace(" ", ""),
    ITEM_DESC = t.Element("ITEM_DESC").Value.Replace(" ", ""),
    ITEM_CATEGORY_CODE = t.Element("ITEM_CATEGORY_CODE").Value.Replace(" ", ""),
    PRIMARY_UOM_CODE = t.Element("PRIMARY_UOM_CODE").Value.Replace(" ", "") //注意此处用到 attribute
    };

      XDocument Contacts =XDocument.Load("XMLFile1.xml");

                        //XElement Contacts = XElement.Parse(xmldata);

                        var Elist =from t in Contacts.Descendants("HEADER")

                                   selectnew

                                   {

                                       CREATION_DATE = t.Element("CREATION_DATE").Value.Replace(" ", ""),

                                       ITEM_NUMBER = t.Element("ITEM_NUMBER").Value.Replace(" ", ""),

                                       ITEM_DESC = t.Element("ITEM_DESC").Value.Replace(" ", ""),

                                       ITEM_CATEGORY_CODE = t.Element("ITEM_CATEGORY_CODE").Value.Replace(" ", ""),

                                       PRIMARY_UOM_CODE = t.Element("PRIMARY_UOM_CODE").Value.Replace(" ", "")   //注意此处用到 attribute

                                   };

  • 相关阅读:
    去除Html标签
    asp.net弹出多个模态窗口
    window.returnValue的用法
    eTerm-用于报价的指令(GK状态码的使用)
    使用ffmpeg 操作音频文件前后部分静音移除.
    使用Visual Studio 2017开发python,并在iis上部署Python Django
    解决wampserver 服务无法启动
    网站优化记录-通过命令预编译Asp.net 网站,成功优化到毫秒级别。
    Scut游戏引擎改造兼容Codis。
    windows修改Host后未生效。
  • 原文地址:https://www.cnblogs.com/ggdxx/p/4942640.html
Copyright © 2011-2022 走看看