Delete tag New
and its content if the next tag is <b>
here is my xml file
<tag>
<New>some content</New>
<b> bold </b>
<New> content two </New>
<p> p tag </p>
</tag>
output is
<tag>
<b> bold </b>
<New> content two </New>
<p> p tag </p>
</tag>
here is my code
XElement rootImg = XElement.Parse(xml string variable);
IEnumerable<XElement> img =
from el in rootImg.Descendants("New").ToList()
select el;
foreach (XElement el in img)
{
//what am i going to do here?
}
foreach (XElement el in img.ToArray())
{
var afterElement = el.NodesAfterSelf().FirstOrDefault() as XElement;
if (afterElement != null && afterElement.Name == "b")
{
el.Remove();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.