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

  • <tfoot id='vg6dQ'></tfoot>
    <legend id='vg6dQ'><style id='vg6dQ'><dir id='vg6dQ'><q id='vg6dQ'></q></dir></style></legend>

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

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

        檢測 XML 的更好方法?

        Better way to detect XML?(檢測 XML 的更好方法?)

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

        <legend id='MmHRg'><style id='MmHRg'><dir id='MmHRg'><q id='MmHRg'></q></dir></style></legend>
          <tbody id='MmHRg'></tbody>

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

                • 本文介紹了檢測 XML 的更好方法?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  目前,我有以下 c# 代碼從文本中提取值.如果是 XML,我想要其中的值 - 否則,如果不是 XML,它可以只返回文本本身.

                  字符串數據 = "..."嘗試{返回 XElement.Parse(data).Value;}捕捉(System.Xml.XmlException){返回數據;}

                  我知道異常在 C# 中很昂貴,所以我想知道是否有更好的方法來確定我正在處理的文本是否為 xml?

                  我想到了正則表達式測試,但我不認為這是一個更便宜的選擇.請注意,我要求的是一種更便宜的方法.

                  解決方案

                  你可以對

                  做一個初步的檢查.因為所有 XML 都必須以 1 開頭,而所有非 XML 的大部分都不會以 1 開頭.

                  (手寫.)

                  //長度必須是 XMLif (!string.IsNullOrEmpty(data)){//如果它以 < 開頭修剪后可能是XML//如果字符串全是空格,需要再次進行空檢查.var trimmedData = data.TrimStart();if (string.IsNullOrEmpty(trimmedData)){返回數據;}if (trimmedData[0] == '<'){嘗試{返回 XElement.Parse(data).Value;}捕捉(System.Xml.XmlException){返回數據;}}}別的{返回數據;}

                  我最初使用的是正則表達式,但 Trim()[0] 與該正則表達式的作用相同.

                  Currently, I have the following c# code to extract a value out of text. If its XML, I want the value within it - otherwise, if its not XML, it can just return the text itself.

                  String data = "..."
                  try
                  {
                      return XElement.Parse(data).Value;
                  }
                  catch (System.Xml.XmlException)
                  {
                      return data;
                  }
                  

                  I know exceptions are expensive in C#, so I was wondering if there was a better way to determine if the text I'm dealing with is xml or not?

                  I thought of regex testing, but I dont' see that as a cheaper alternative. Note, I'm asking for a less expensive method of doing this.

                  解決方案

                  You could do a preliminary check for a < since all XML has to start with one and the bulk of all non-XML will not start with one.

                  (Free-hand written.)

                  // Has to have length to be XML
                  if (!string.IsNullOrEmpty(data))
                  {
                      // If it starts with a < after trimming then it probably is XML
                      // Need to do an empty check again in case the string is all white space.
                      var trimmedData = data.TrimStart();
                      if (string.IsNullOrEmpty(trimmedData))
                      {
                         return data;
                      }
                  
                      if (trimmedData[0] == '<')
                      {
                          try
                          {
                              return XElement.Parse(data).Value;
                          }
                          catch (System.Xml.XmlException)
                          {
                              return data;
                          }
                      }
                  }
                  else
                  {
                      return data;
                  }
                  

                  I originally had the use of a regex but Trim()[0] is identical to what that regex would do.

                  這篇關于檢測 XML 的更好方法?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯誤的 XML)
                  <legend id='w7aG8'><style id='w7aG8'><dir id='w7aG8'><q id='w7aG8'></q></dir></style></legend>
                  <i id='w7aG8'><tr id='w7aG8'><dt id='w7aG8'><q id='w7aG8'><span id='w7aG8'><b id='w7aG8'><form id='w7aG8'><ins id='w7aG8'></ins><ul id='w7aG8'></ul><sub id='w7aG8'></sub></form><legend id='w7aG8'></legend><bdo id='w7aG8'><pre id='w7aG8'><center id='w7aG8'></center></pre></bdo></b><th id='w7aG8'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='w7aG8'><tfoot id='w7aG8'></tfoot><dl id='w7aG8'><fieldset id='w7aG8'></fieldset></dl></div>

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

                        <tbody id='w7aG8'></tbody>
                      <tfoot id='w7aG8'></tfoot>

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

                          • 主站蜘蛛池模板: 久在线 | 欧美一区二区三区久久精品 | 日韩综合在线 | 久久久亚洲精品视频 | 涩涩导航| 成人国产毛片 | 日韩一区二区视频 | 国产高清在线精品 | 成人午夜电影在线观看 | 久久精品成人热国产成 | 欧美手机在线 | 欧美区在线 | 国产中文字幕在线 | 日本成人综合 | 欧美精品综合 | 中文字幕免费视频 | 国产高清免费在线 | 国产日韩欧美一区二区在线播放 | 免费av在线网站 | 一区二区三区四区在线播放 | 国产特黄一级 | 蜜桃官网| 久久国产婷婷国产香蕉 | 超碰人人人 | 日韩精品在线看 | 午夜激情视频在线 | 欧美视频免费 | 久久在线看| 一色桃子av一区二区 | 天堂在线免费视频 | 精品自拍视频在线观看 | 久久久蜜臀国产一区二区 | 麻豆91精品91久久久 | 久久久高清 | 亚洲热在线视频 | 亚洲一区二区三区高清 | 婷婷国产一区二区三区 | 美女视频一区 | 亚洲欧美视频一区 | 中文字幕在线观看第一页 | 亚洲色在线视频 |