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

                                   };

  • 相关阅读:
    Duilib 入门教程: 怎么创建一个自定义的窗口
    从屏幕右下角升起的弹窗
    最小化窗口至右下角
    MFC 使程序不在任务栏显示
    创建数据库
    sqlite入门基础(一):sqlite3_open,sqlite3_exec,slite3_close
    VC++、MFC中最好的开源项目
    在MFC中,利用GDI绘制橡皮筋效果-直线,圆,椭圆,矩形
    WCHAR char CString等常用类型互转
    CGAL 计算机几何算法库
  • 原文地址:https://www.cnblogs.com/ggdxx/p/4942640.html
Copyright © 2011-2022 走看看