久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='cqyRz'></bdo><ul id='cqyRz'></ul>
      1. <legend id='cqyRz'><style id='cqyRz'><dir id='cqyRz'><q id='cqyRz'></q></dir></style></legend>

      2. <small id='cqyRz'></small><noframes id='cqyRz'>

        <tfoot id='cqyRz'></tfoot>

        <i id='cqyRz'><tr id='cqyRz'><dt id='cqyRz'><q id='cqyRz'><span id='cqyRz'><b id='cqyRz'><form id='cqyRz'><ins id='cqyRz'></ins><ul id='cqyRz'></ul><sub id='cqyRz'></sub></form><legend id='cqyRz'></legend><bdo id='cqyRz'><pre id='cqyRz'><center id='cqyRz'></center></pre></bdo></b><th id='cqyRz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='cqyRz'><tfoot id='cqyRz'></tfoot><dl id='cqyRz'><fieldset id='cqyRz'></fieldset></dl></div>
      3. 刪除沒有子節(jié)點(diǎn)的父節(jié)點(diǎn)

        remove parent node without childs nodes(刪除沒有子節(jié)點(diǎn)的父節(jié)點(diǎn))
          <tbody id='iyBMU'></tbody>

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

          <bdo id='iyBMU'></bdo><ul id='iyBMU'></ul>

          <tfoot id='iyBMU'></tfoot>

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

            <legend id='iyBMU'><style id='iyBMU'><dir id='iyBMU'><q id='iyBMU'></q></dir></style></legend>

                  本文介紹了刪除沒有子節(jié)點(diǎn)的父節(jié)點(diǎn)的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個(gè)關(guān)于從 xml 文件中刪除特定節(jié)點(diǎn)的問題.

                  I have a question related to removing specific nodes from xml file.

                  這是我的 XML 示例:

                  Here is my sample of XML:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <root>
                    <nodeA attribute="1">
                      <nodeB attribute="table">
                        <nodeC attribute="500"></nodeC>
                        <nodeC attribute="5"></nodeC>
                      </nodeB>
                      <nodeB attribute="3">
                        <nodeC attribute="4"></nodeC>
                        <nodeC attribute="5"></nodeC>
                        <nodeC attribute="5"></nodeC>
                      </nodeB>
                      <nodeB attribute="placeHolder">
                      <nodeB attribute="toRemove">
                        <nodeB attribute="glass"></nodeB>
                          <nodeE attribute="7"></nodeE>
                        <nodeB attribute="glass"></nodeB>
                        <nodeB attribute="glass"></nodeB>
                      </nodeB>
                      </nodeB>
                      <nodeB attribute="3">
                        <nodeC attribute="4"></nodeC>
                        <nodeC attribute="5"></nodeC>
                        <nodeC attribtue="5"></nodeC>
                       </nodeB>
                      <nodeB attribute="placeHolder">
                      <nodeB attribute="toRemove">
                        <nodeB attribute="glass"></nodeB>
                          <nodeE attribute="7"></nodeE>
                        <nodeB attribute="glass"></nodeB>
                        <nodeB attribute="glass"></nodeB>
                      </nodeB>
                      </nodeB>
                    </nodeA>
                  </root>
                  

                  我想刪除節(jié)點(diǎn) nodeB="toRemove" 而不刪除該節(jié)點(diǎn)的子節(jié)點(diǎn).之后我需要對 nodeB attribute="placeHolder" 做同樣的事情.部分結(jié)果如下所示:

                  I would like to remove node nodeB="toRemove" without removing childrens of this node. After that I need to do same thing with nodeB attribute="placeHolder". Part of result would look like that:

                       <nodeB attribute="3">
                        <nodeC attribute="4"></nodeC>
                        <nodeC attribute="5"></nodeC>
                        <nodeC attribtue="5"></nodeC>
                       </nodeB>
                       <nodeB attribute="glass"></nodeB>
                          <nodeE attribute="7"></nodeE>
                       <nodeB attribute="glass"></nodeB>
                       <nodeB attribute="glass"></nodeB>
                  

                  我一直在嘗試這樣的代碼來實(shí)現(xiàn):

                  I have been trying code like this to achive that:

                          XmlNodeList nodeList = doc.SelectNodes("http://nodeB[@attribute="toRemove"]");
                  
                          foreach (XmlNode node in nodeList)
                          {
                              foreach (XmlNode child in node.ChildNodes)
                              {
                                  node.ParentNode.AppendChild(child);
                              }
                              node.ParentNode.RemoveChild(node);
                          }
                          doc.Save(XmlFilePathSource);
                  

                  我能夠找到具有所需屬性 toRemove 或 placeHolder 的節(jié)點(diǎn),但是我無法將此節(jié)點(diǎn)的子節(jié)點(diǎn)上移一級.在這種情況下你能幫我嗎?它可以是 Linq、XDocument、XmlReader 的解決方案,但我更喜歡使用 XmlDocument.感謝您提前為我提供的任何幫助.

                  I am able to locate node with desired attribute toRemove or placeHolder, however I am not able to move children of this nodes up by one level. Could you help me in this case? It can be solution with Linq, XDocument, XmlReader but I prefer working with XmlDocument. Thank you for any help you could provide me in advance.

                  在這種情況下,我使用了 Chuck Savage 在下面編寫的稍微修改過的代碼(以保持順序).一次刪除

                  In this case I have used slightly modified code(to preserve order) that Chuck Savage wrote bellow. Once to remove

                    <nodeB attribute="toRemove"> </nodeB>
                  

                  然后對

                    <nodeB attribute="placeHolder"></nodeB>
                  

                  這里是稍微修改的代碼

                    XElement root = XElement.Load(XmlFilePathSource); 
                    var removes = root.XPathSelectElements("http://nodeB[@attribute="toRemove"]");
                    foreach (XElement node in removes.ToArray())
                    {
                      node.Parent.AddAfterSelf(node.Elements());
                      node.Remove();
                    }
                    root.Save(XmlFilePathSource);
                  

                  @MiMo 提供的 xslt 方法在這種情況下也非常有用.

                  xslt approach provided by @MiMo is very useful as well in this case.

                  推薦答案

                  使用 Linq-to-XML 和您的 XPath,

                  Using Linq-to-XML and your XPath,

                  XElement root = XElement.Load(XmlFilePathSource); // or .Parse(string)
                  var removes = root.XPathSelectElements("http://nodeB[@attribute="toRemove"]");
                  foreach (XElement node in removes.ToArray())
                  {
                      node.AddBeforeSelf(node.Elements());
                      node.Remove();
                  }
                  root.Save(XmlFilePathSource);
                  

                  注意:XPath 在 System.Xml.XPath

                  Note: XPath is available in System.Xml.XPath

                  注意 2:您可以使用 這些擴(kuò)展 與 XmlDocument 進(jìn)行轉(zhuǎn)換,因?yàn)槟矚g XmlDocument.

                  Note2: You can convert to/from XmlDocument using these extensions since you prefer XmlDocument.

                  這篇關(guān)于刪除沒有子節(jié)點(diǎn)的父節(jié)點(diǎn)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 時(shí)忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  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(解析格式錯(cuò)誤的 XML)

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

                  <tfoot id='prG7Q'></tfoot>
                  <legend id='prG7Q'><style id='prG7Q'><dir id='prG7Q'><q id='prG7Q'></q></dir></style></legend>

                    • <bdo id='prG7Q'></bdo><ul id='prG7Q'></ul>
                    • <i id='prG7Q'><tr id='prG7Q'><dt id='prG7Q'><q id='prG7Q'><span id='prG7Q'><b id='prG7Q'><form id='prG7Q'><ins id='prG7Q'></ins><ul id='prG7Q'></ul><sub id='prG7Q'></sub></form><legend id='prG7Q'></legend><bdo id='prG7Q'><pre id='prG7Q'><center id='prG7Q'></center></pre></bdo></b><th id='prG7Q'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='prG7Q'><tfoot id='prG7Q'></tfoot><dl id='prG7Q'><fieldset id='prG7Q'></fieldset></dl></div>
                              <tbody id='prG7Q'></tbody>
                            主站蜘蛛池模板: 欧美一区二区黄 | 免费久久精品视频 | 一区二区三区欧美在线观看 | 亚洲国产成人精品女人久久久 | 午夜影院黄 | 亚洲区一区二 | 亚州影院 | 久久久噜噜噜久久中文字幕色伊伊 | 日本在线网站 | 黄色一级大片在线免费看产 | 欧美老妇交乱视频 | 成人免费看黄网站在线观看 | 成人免费观看视频 | 四虎影院在线观看av | 欧美二区在线 | 亚洲精品久久久久久国产精华液 | 免费一级淫片aaa片毛片a级 | 米奇狠狠鲁 | 成人国内精品久久久久一区 | 亚洲一区二区精品视频在线观看 | 嫩草视频在线免费观看 | 欧美天天视频 | 欧美久久国产精品 | 九九精品在线 | 日韩看片 | av网站观看| 成人免费视频观看 | 免费人成在线观看网站 | 亚洲精品久久久久久国产精华液 | 嫩草懂你的影院入口 | 国产精品日韩欧美一区二区三区 | 亚洲天堂av在线 | 日日夜夜天天干 | 成人在线小视频 | 毛片韩国 | 久久久久国产成人精品亚洲午夜 | 亚欧洲精品在线视频免费观看 | 国产小视频自拍 | 亚洲欧美在线免费观看 | 国产高清视频在线 | 国产精品欧美一区二区三区 |