【问题标题】:How to remove <p> like tags from xml using c#如何使用 c# 从 xml 中删除 <p> 之类的标签
【发布时间】:2015-11-16 11:19:39
【问题描述】:

这是我的xml,

<Description>
   <p><br>In house music panel.<br>Safe deposit box.<br>All modern and high quality installation and amenities.<br><br><br><b>All inclusive formula</b><br>Breakfast open buffet<br>Lunch open buffet<br>dinner open buffet<br>From 11.00 AM till 23.00 HRS<br>Water (Small Bottle)<br>Soft drinks<br>Local beer (Served by glass)<br>Local wine (Only during lunch and dinner)</p><p><br><b><b>The Program includes:</b><br></b>♦ 07 nights’ accommodation on board of MS b><br></b></p><p><b>Attraction - Combo Light Package</b><br>Visit to the east Bank, Karnak and Luxor temples, Visit the Temple shared by two gods Sobek and Haeroris in Kom Ombo afternoon, Morning visit to High dam, Phila   temple<br><b><br>Attraction - Combo Full Package Excursions</b><br>Visit to the East Bank, Karnak and Luxor temples, Visit the Temple shared by two gods Sobek and Haeroris in Kom Ombo afternoon, Visit Edfu Temple, Morning visit to High dam, Philae temple and unfinished obelisk, on return visits West bank, Hatsheput, Valley of the Kings, Memmon colossi Esna Temple<br><br><b>Attraction - Cruise Signature Program</b><br>Visit Dier-al-Madina + Habu Temple + Valley of the Nobles, Dendra Temple by bus + Temple of Hathor-Cript, Edfu OR Kom Ombo Temple (up to the customer) Kalabsha trip + Botanical Gardens + 01 hour felucca </p>
</Description>

内部描述标签包括&lt;p&gt;&lt;b&gt;标签。我怎样才能删除这些。

这是我的代码,

 var product = from a in cruiseDoc.Descendants("CruiseProduct")
                  select new CProducts
                  {
                      cId = a.Element("ID").Value,
                      cName = a.Element("Name").Value,
                      cDescription= a.Element("Description").Value// need for this
                  };

【问题讨论】:

  • 不明白你的意思。请说明问题所在。
  • 你知道那不是有效的 XML 吗?
  • 这是我的网络服务,我想要的是在 标记内显示没有


    字符的数据

  • 请注意:html != xml
  • @anu - 是的,但它不是有效的 XML。在您提出问题之前,您需要修复源代码以便它生成有效的 XML。

标签: c# regex xml


【解决方案1】:

我找到了答案...

var product = from a in cruiseDoc.Descendants("CruiseProduct")
                  select new CProducts
                  {
                      cId = a.Element("ID").Value,
                      cName = a.Element("Name").Value,
                      cDescription= Regex.Replace(a.Element("Description").Value, "<.*?>", string.Empty)
                  };

【讨论】:

    【解决方案2】:

    一个快速的解决办法是做

    var regex=@"(?<=\<Description\>.*?)\<\/?(br|p)\>(?=.*?\<\/Description\>)";
    var output=Regex.Replace(input,regex,"");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      相关资源
      最近更新 更多