• 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

                                   };

  • 相关阅读:
    Flume基础(一):概述
    Hive高级(2):优化(2) 表的优化
    ospf命令
    Verizon 和某 BGP 优化器如何在今日大范围重创互联网
    BGP数据中心鉴别方法
    多线BGP鉴定
    mpls ldp neighbor 和loopbak
    ospf默认路由
    ospf
    ubuntu cloud init获取元数据失败
  • 原文地址:https://www.cnblogs.com/ggdxx/p/4942640.html
Copyright © 2020-2023  润新知