• 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

                                   };

  • 相关阅读:
    Linux软件安装之JDK的安装
    VMWARE虚拟机安装系统提示CPU已被客户机操作系统禁用和secureCUT乱码
    联网配置及静态更改
    全文搜索技术--Solr7.1之配置中文分析器
    全文搜索技术--solr7.1之mysql的安装步骤
    建立主从的九大步及配置哨兵
    mysql 模糊匹配优化(全文索引)
    微服务架构的身份验证解决方案
    spring声明式事务回滚
    spring 通过@responsebody接收多个对象参数
  • 原文地址:https://www.cnblogs.com/ggdxx/p/4942640.html
Copyright © 2020-2023  润新知