[英]how do I eliminate elements with certain Ancestors?
I'm trying to set the value of all "CSS" elements "value" to "", here is the code: 我正在尝试将所有“ CSS”元素“ value”的值设置为“”,这是代码:
XDocument doc = XDocument.Load(fi.FullName);
XNamespace rep = "http://developer.cognos.com/schemas/report/8.0/";
List<XElement> cssElements =
(from e in doc.Root.DescendantsAndSelf(rep + "CSS")
where
(
(e.Attribute("value") != null)
)
select e).ToList();
//modify Attribute in elements
foreach (XElement xe in cssElements)
{
xe.Attribute("value").Value = "";
}
But, I don't want to modify this one CSS, which has as ancestors "crosstab" and "style" (xml below): 但是,我不想修改这一CSS,因为它的祖先是“ crosstab”和“ style”(下面的xml):
<crosstab name="Crosstab1" refQuery="Query1">
<crosstabSuppress type="rows"/>
<style>
<CSS value="border-collapse:collapse;font-family:'Times New Roman'"/>
how can I do that? 我怎样才能做到这一点? Thanks! 谢谢!
If I understood you correctly, maybe something like this: 如果我对您的理解正确,也许是这样的:
...
List<XElement> cssElements =
(from e in doc.Root.DescendantsAndSelf(rep + "CSS")
where
(
(e.Attribute("value") != null) && !(e.Ancestors(rep + "style").Any() && e.Ancestors(rep + "crosstab").Any())
)
select e).ToList();
...
I only added this to your where
-clause: 我只加给你的where
-clause:
&& !(e.Ancestors(rep + "style").Any() && e.Ancestors(rep + "crosstab").Any())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.