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

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

      <tfoot id='o2MMG'></tfoot>

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

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

        在 C# 中讀取帶有未閉合標簽的 XML

        Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)

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

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

              <tfoot id='VWug3'></tfoot>
                <bdo id='VWug3'></bdo><ul id='VWug3'></ul>
                <legend id='VWug3'><style id='VWug3'><dir id='VWug3'><q id='VWug3'></q></dir></style></legend>
                • 本文介紹了在 C# 中讀取帶有未閉合標簽的 XML的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個程序可以運行測試并生成一個包含所有結果的網格視圖,以及一個 XML 日志文件.該程序還具有加載日志以復制網格視圖的功能.

                  I have a program which runs tests and generates a grid-view with all the results in it, and also an XML log file. The program also has the functionality to load logs to replicate the grid-view.

                  由于程序在執行時寫入日志文件,如果它崩潰,日志文件將缺少結束標記.我仍然希望能夠加載這些 XML 文件,因為仍然有很多有價值的數據可以幫助我找出導致崩潰的原因.

                  Since the program writes to the log file as its executing, if it crashes the log file will be missing closing tags. I still want to be able to load these XML files though as there is still lots of valuable data that can help me find out what caused the crash.

                  我在想也許可以通過 XML 文件并關閉任何未關閉的 XML 標記,或者可能編寫某種臟"XML 閱讀器來假裝每個標記都已關閉.關于我可以做什么或應該如何進行的任何想法?

                  I was thinking maybe going through the XML file and closing off any unclosed XML tag, or maybe writing some kind of "Dirty" XML reader that would pretend every tag was closed. Any ideas on what I could do or how I should proceed?

                  <Root>
                    <Parent>
                       <Child Name="One">
                          <Foo>...</Foo>
                          <Bar>...</Bar>
                          <Baz>...</Baz>
                       </Child>
                       <Child Name="Two">
                          <Foo>...</Foo>
                          <Bar>...</Bar>
                   !-- Crash happens here --!
                  

                  從此我仍然會期待生產

                   Child   Foo   Bar   Baz
                   One     ...   ...   ...
                   Two     ...   ...    /
                  

                  推薦答案

                  大概它在被截斷之前都是有效的......所以使用 XmlReader 可以工作......只是準備好處理它吧當它到達截斷點時.

                  Presumably it's all valid until it's truncated... so using XmlReader could work... just be prepared to handle it going bang when it reaches the truncation point.

                  現在 XmlReader API 不是特別好 (IMO),所以您可能想要移動到一些有趣數據的開頭(這些數據本身必須是完整的),然后調用 XNode.ReadFrom(XmlReader) 方法以簡單易用的形式獲取該數據.然后移動到下一個元素的開頭并執行相同的操作,等等.

                  Now the XmlReader API isn't terribly pleasant (IMO) so you might want to move to the start of some interesting data (which would have to be complete in itself) and then call the XNode.ReadFrom(XmlReader) method to get that data in a simple-to-use form. Then move to the start of the next element and do the same, etc.

                  示例代碼:

                  using System;
                  using System.Linq;
                  using System.Xml;
                  using System.Xml.Linq;
                  
                  class Program
                  {
                      static void Main(string[] args)
                      {
                          using (XmlReader reader = XmlReader.Create("test.xml"))
                          {
                              while (true)
                              {
                                  while (reader.NodeType != XmlNodeType.Element ||
                                      reader.LocalName != "Child")
                                  {
                                      if (!reader.Read())
                                      {
                                          Console.WriteLine("Finished!");
                                      }
                                  }
                                  XElement element = (XElement) XNode.ReadFrom(reader);
                                  Console.WriteLine("Got child: {0}", element.Value);
                              }
                          }
                      }
                  }
                  

                  示例 XML:

                  <Root>
                    <Parent>
                      <Child>First child</Child>
                      <Child>Second child</Child>
                      <Child>Broken
                  

                  樣本輸出:

                  得到孩子:第一個孩子得到孩子:第二個孩子

                  Got child: First child Got child: Second child

                  Unhandled Exception: System.Xml.XmlException: Unexpected end of file has occurred
                  The following elements are not closed: Child, Parent, Root. Line 5, position 18.
                     at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
                     at System.Xml.XmlTextReaderImpl.ParseElementContent()
                     at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
                     at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
                     at System.Xml.Linq.XElement.ReadElementFrom(XmlReader r, LoadOptions o)
                     at System.Xml.Linq.XNode.ReadFrom(XmlReader reader)
                     at Program.Main(String[] args)
                  

                  所以很明顯你想捕捉異常,但你可以看到它成功地讀取了前兩個元素.

                  So obviously you'd want to catch the exception, but you can see that it managed to read the first two elements correctly.

                  這篇關于在 C# 中讀取帶有未閉合標簽的 XML的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  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 僅提取頁面文本)
                      <bdo id='uJypM'></bdo><ul id='uJypM'></ul>

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

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

                        1. <tfoot id='uJypM'></tfoot>
                            <tbody id='uJypM'></tbody>

                          • <legend id='uJypM'><style id='uJypM'><dir id='uJypM'><q id='uJypM'></q></dir></style></legend>

                            主站蜘蛛池模板: 91久久久久久久 | www.国产精品 | 一区二区不卡 | 麻豆精品一区二区三区在线观看 | 欧美精品一区在线发布 | 久久久人| 在线视频成人 | 欧美一区二区三区在线播放 | 日韩三区在线 | 欧美日韩亚 | 久草视频网站 | 狠狠久 | 在线色网址| 视频二区 | 亚洲欧美在线观看视频 | 亚洲狠狠爱 | 日韩欧美在线观看 | 337p日本欧洲亚洲大胆精蜜臀 | 国产精品永久免费视频 | 国产精品亚洲视频 | 特级做a爱片免费69 精品国产鲁一鲁一区二区张丽 | 欧美久久不卡 | 欧美一区二区视频 | 欧美9999| 国产在线一区二区 | 久久久国产一区二区三区 | 国产精品久久久久久久久久久新郎 | 久草在线影 | 欧美一区二区三区在线观看 | 国产成人精品综合 | 成人免费在线小视频 | 亚洲国产欧美国产综合一区 | 中文字幕乱码亚洲精品一区 | 国产98色在线 | 免费在线观看黄网站 | 国产精品亚洲一区二区三区在线 | 亚洲三级免费看 | 日韩美av | 日韩中文字幕第一页 | 日本高清中文字幕 | 日本视频一区二区三区 |