如何使用c#从xml中删除<p>之类的标签

时间:2015-11-16 11:19:39

标签: c# regex xml

这是我的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>

内部描述标记包含<p><b>标记。我该如何删除它们。

这是我的代码,

 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
                  };

2 个答案:

答案 0 :(得分: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)
                  };

答案 1 :(得分:0)

快速解决方法是

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