pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  1. <small id='G32di'></small><noframes id='G32di'>

  2. <tfoot id='G32di'></tfoot>

    <i id='G32di'><tr id='G32di'><dt id='G32di'><q id='G32di'><span id='G32di'><b id='G32di'><form id='G32di'><ins id='G32di'></ins><ul id='G32di'></ul><sub id='G32di'></sub></form><legend id='G32di'></legend><bdo id='G32di'><pre id='G32di'><center id='G32di'></center></pre></bdo></b><th id='G32di'></th></span></q></dt></tr></i><div class="j3xn2g8" id='G32di'><tfoot id='G32di'></tfoot><dl id='G32di'><fieldset id='G32di'></fieldset></dl></div>
    • <bdo id='G32di'></bdo><ul id='G32di'></ul>
    <legend id='G32di'><style id='G32di'><dir id='G32di'><q id='G32di'></q></dir></style></legend>

    1. 帶有檢查空元素的 XML 到 LINQ

      XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)

          • <bdo id='rx2mR'></bdo><ul id='rx2mR'></ul>

                <tbody id='rx2mR'></tbody>
              <i id='rx2mR'><tr id='rx2mR'><dt id='rx2mR'><q id='rx2mR'><span id='rx2mR'><b id='rx2mR'><form id='rx2mR'><ins id='rx2mR'></ins><ul id='rx2mR'></ul><sub id='rx2mR'></sub></form><legend id='rx2mR'></legend><bdo id='rx2mR'><pre id='rx2mR'><center id='rx2mR'></center></pre></bdo></b><th id='rx2mR'></th></span></q></dt></tr></i><div class="whfxot8" id='rx2mR'><tfoot id='rx2mR'></tfoot><dl id='rx2mR'><fieldset id='rx2mR'></fieldset></dl></div>
            1. <legend id='rx2mR'><style id='rx2mR'><dir id='rx2mR'><q id='rx2mR'></q></dir></style></legend>

                <small id='rx2mR'></small><noframes id='rx2mR'>

              • <tfoot id='rx2mR'></tfoot>

              • 本文介紹了帶有檢查空元素的 XML 到 LINQ的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我面臨的情況是使用 Linq 將 XML 文檔解析為對象.在解析過程中,我正在檢查以確保元素不為空,然后再繼續(xù)解析它們的值.有沒有辦法簡化這句話?

                The situation I am faced with is parsing an XML document into an object using Linq. During the parse I am checking to make sure Elements are not null before proceeding to parse out their values. Is there anyway to simplify this statement?

                  var variable = (from x in xdoc.Descendants("Root")
                                 select new AccountingResponse
                                 {      
                                 NetCharge = x.Element("Charges") != null && x.Element("Charges").Element("NetCharge") != null ? x.Element("Charges").Element("NetCharge").Value : "0",
                                 TotalCharge = x.Element("Charges") != null && x.Element("Charges").Element("TotalCharge") != null ? x.Element("Charges").Element("TotalCharge").Value : "0"
                                 }).SingleOrDefault();
                

                總而言之,我不想繼續(xù)檢查每行是否存在節(jié)點.我知道我可以在解析之前測試該節(jié)點是否存在,但可能還有其他數(shù)據(jù)需要解析以創(chuàng)建 AccountingResponse,我想避免一次只解析一部分 XML 的 if 語句.

                To summarize, I do not want to continue to check if the nodes exist on each line. I know I can test to see if the node exists prior to the parsing, but there may be other data that needs parsed to create the AccountingResponse and I want to avoid if statements that only parse a portion of the XML out at a time.

                或者也許我做錯了,有更好的方法!

                Or perhaps I'm doing this completely wrong and there's a better way!

                推薦答案

                一個簡單的選擇是使用 Elements 而不是 Element - 這將返回一個零長度的序列如果元素不存在.所以你可以使用:

                One simple option is to use Elements rather than Element - that will return a zero-length sequence if the element isn't present. So you can use:

                from x in xdoc.Descendants("Root")
                select new AccountingResponse
                {      
                    NetCharge = x.Elements("Charges")
                                 .Elements("NetCharge")
                                 .Select(y => (int) y)
                                 .FirstOrDefault(),
                    TotalCharge = x.Elements("Charges")
                                   .Elements("TotalCharge")
                                   .Select(y => (int) y)
                                   .FirstOrDefault(),
                }).SingleOrDefault();
                

                (請注意,您的原始代碼不會編譯,因為 Value 是一個字符串,而 0 是一個 int...)

                (Note that your original code wouldn't compile, as Value is a string whereas 0 is an int...)

                這篇關(guān)于帶有檢查空元素的 XML 到 LINQ的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標(biāo)簽的 XML)
                Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                Parse malformed XML(解析格式錯誤的 XML)
                extracting just page text using HTMLAgilityPack(使用 HTMLAgilityPack 僅提取頁面文本)
                <legend id='7Tipo'><style id='7Tipo'><dir id='7Tipo'><q id='7Tipo'></q></dir></style></legend>

              • <i id='7Tipo'><tr id='7Tipo'><dt id='7Tipo'><q id='7Tipo'><span id='7Tipo'><b id='7Tipo'><form id='7Tipo'><ins id='7Tipo'></ins><ul id='7Tipo'></ul><sub id='7Tipo'></sub></form><legend id='7Tipo'></legend><bdo id='7Tipo'><pre id='7Tipo'><center id='7Tipo'></center></pre></bdo></b><th id='7Tipo'></th></span></q></dt></tr></i><div class="jcqsk3q" id='7Tipo'><tfoot id='7Tipo'></tfoot><dl id='7Tipo'><fieldset id='7Tipo'></fieldset></dl></div>
                <tfoot id='7Tipo'></tfoot>

                    <tbody id='7Tipo'></tbody>
                    • <bdo id='7Tipo'></bdo><ul id='7Tipo'></ul>
                    • <small id='7Tipo'></small><noframes id='7Tipo'>

                          主站蜘蛛池模板: 同步带轮_同步带_同步轮_iHF合发齿轮厂家-深圳市合发齿轮机械有限公司 | 沥青车辙成型机-车托式混凝土取芯机-混凝土塑料试模|鑫高仪器 | 今日娱乐圈——影视剧集_八卦娱乐_明星八卦_最新娱乐八卦新闻 | nalgene洗瓶,nalgene量筒,nalgene窄口瓶,nalgene放水口大瓶,浙江省nalgene代理-杭州雷琪实验器材有限公司 | 西门子伺服控制器维修-伺服驱动放大器-828D数控机床维修-上海涌迪 | 阳光1号桔柚_无核沃柑_柑橘新品种枝条苗木批发 - 苧金网 | 低噪声电流前置放大器-SR570电流前置放大器-深圳市嘉士达精密仪器有限公司 | 锻造液压机,粉末冶金,拉伸,坩埚成型液压机定制生产厂家-山东威力重工官方网站 | arch电源_SINPRO_开关电源_模块电源_医疗电源-东佑源 | 拉力测试机|材料拉伸试验机|电子拉力机价格|万能试验机厂家|苏州皖仪实验仪器有限公司 | 宁夏档案密集柜,智能密集柜,电动手摇密集柜-盛隆柜业宁夏档案密集柜厂家 | BESWICK球阀,BESWICK接头,BURKERT膜片阀,美国SEL继电器-东莞市广联自动化科技有限公司 | 5nd音乐网|最新流行歌曲|MP3歌曲免费下载|好听的歌|音乐下载 免费听mp3音乐 | 挤奶设备过滤纸,牛奶过滤纸,挤奶机过滤袋-济南蓝贝尔工贸有限公司 | 数控车床-立式加工中心-多功能机床-小型车床-山东临沂金星机床有限公司 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 杭州顺源过滤机械有限公司官网-压滤机_板框压滤机_厢式隔膜压滤机厂家 | 风电变桨伺服驱动器-风电偏航变桨系统-深圳众城卓越科技有限公司 | 展厅设计-展馆设计-专业企业展厅展馆设计公司-昆明华文创意 | 大型多片锯,圆木多片锯,方木多片锯,板材多片锯-祥富机械有限公司 | 智慧旅游_智慧景区_微景通-智慧旅游景区解决方案提供商 | 中开泵,中开泵厂家,双吸中开泵-山东博二泵业有限公司 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 干培两用箱-细菌恒温培养箱-菲斯福仪器| 【ph计】|在线ph计|工业ph计|ph计厂家|ph计价格|酸度计生产厂家_武汉吉尔德科技有限公司 | 硬度计_影像测量仪_维氏硬度计_佛山市精测计量仪器设备有限公司厂家 | 高效节能电机_伺服主轴电机_铜转子电机_交流感应伺服电机_图片_型号_江苏智马科技有限公司 | 物联网卡_物联网卡购买平台_移动物联网卡办理_移动联通电信流量卡通信模组采购平台? | led全彩屏-室内|学校|展厅|p3|户外|会议室|圆柱|p2.5LED显示屏-LED显示屏价格-LED互动地砖屏_蕙宇屏科技 | 淄博不锈钢无缝管,淄博不锈钢管-鑫门物资有限公司 | 北京四合院出租,北京四合院出售,北京平房买卖 - 顺益兴四合院 | 钢衬四氟管道_钢衬四氟直管_聚四氟乙烯衬里管件_聚四氟乙烯衬里管道-沧州汇霖管道科技有限公司 | 上海新光明泵业制造有限公司-电动隔膜泵,气动隔膜泵,卧式|立式离心泵厂家 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 电缆接头-防爆电缆接头-格兰头-金属电缆接头-防爆填料函 | Safety light curtain|Belt Sway Switches|Pull Rope Switch|ultrasonic flaw detector-Shandong Zhuoxin Machinery Co., Ltd | 模温机-油温机-电加热导热油炉-工业冷水机「欧诺智能」 | 考勤系统_人事考勤管理系统_本地部署BS考勤系统_考勤软件_天时考勤管理专家 | 大巴租车平台承接包车,通勤班车,巴士租赁业务 - 鸿鸣巴士 | 上海平衡机-单面卧式动平衡机-万向节动平衡机-圈带动平衡机厂家-上海申岢动平衡机制造有限公司 | 污泥烘干机-低温干化机-工业污泥烘干设备厂家-焦作市真节能环保设备科技有限公司 |