久久久久久久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>

        檢測(cè) XML 的更好方法?

        Better way to detect XML?(檢測(cè) 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>

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

                  問題描述

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

                  字符串?dāng)?shù)據(jù) = "..."嘗試{返回 XElement.Parse(data).Value;}捕捉(System.Xml.XmlException){返回?cái)?shù)據(jù);}

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

                  我想到了正則表達(dá)式測(cè)試,但我不認(rèn)為這是一個(gè)更便宜的選擇.請(qǐng)注意,我要求的是一種更便宜的方法.

                  解決方案

                  你可以對(duì)

                  做一個(gè)初步的檢查.因?yàn)樗?XML 都必須以 1 開頭,而所有非 XML 的大部分都不會(huì)以 1 開頭.

                  (手寫.)

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

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

                  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.

                  這篇關(guān)于檢測(cè) XML 的更好方法?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(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)
                  <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>

                          • 主站蜘蛛池模板: 国产精品一卡二卡三卡 | 日韩中文一区 | 国产a一区二区 | 伊人久久综合 | 欧美日韩精品综合 | 午夜视频网站 | 精品国产一区探花在线观看 | 色必久久| 国产精品久久在线 | 成人视屏在线观看 | 欧美精品导航 | 三区四区在线观看 | 91在线观看 | 青青草一区二区 | 久久久999精品| 亚洲免费在线 | 免费三级网 | 国产一区不卡在线观看 | 欧美aaaaaaaa| 午夜影院普通用户体验区 | 美日韩视频 | 久久精品国产一区二区电影 | 亚洲成人精品国产 | 中文字幕日韩在线观看 | 91精品国产色综合久久不卡98口 | 日韩视频国产 | 人人叉 | 免费一区二区 | 9191在线播放| 久久亚洲视频 | 草b视频| 国产精品成人国产乱一区 | 91麻豆精品国产91久久久资源速度 | 一级免费毛片 | 狠狠天天 | 免费在线国产视频 | 91婷婷韩国欧美一区二区 | 欧美美女爱爱 | 蜜桃一区| 久久国产精品72免费观看 | 黄色大片免费观看 |