0
如何使用ling to xml根据其父元素属性检索特定的子元素?如何通过属性获取页面上的元素
例如,如果我从xml文档中提取以下内容,我想改变TextAlign的值。可能有几个文本框对象,从而硬编码的查询是没有用的:
<Textbox Name="pageHeaderReportTitle">
<CanGrow>true</CanGrow>
<Height>1cm</Height>
<Left>45pt</Left>
<Style>
<BackgroundColor>#4F81BD</BackgroundColor>
<Color>White</Color>
<FontSize>14pt</FontSize>
<FontWeight>700</FontWeight>
<TextAlign>Left</TextAlign>
<VerticalAlign>Middle</VerticalAlign>
</Style>
<Top>90pt</Top>
<Value>=iif(len("") > 0 ,iif(len("Employees") > 0,"Employees - ",""),"Employees")</Value>
<Width>289.1614mm</Width>
<ZIndex>1</ZIndex>
</Textbox>
这里是我的尝试 - >编译器没有按;吨compain,但它并没有设置XML doc..When的价值调试,编译器抱怨“对象引用不设置到对象的实例。”:
var thisIsTheNode = (from data in rep.ReportDefinitionDoc.Descendants(ns + "Textbox")
where data.Attribute("Name").Value == "pageHeaderReportTitle"
select data.Element("Width")).FirstOrDefault();
thisIsTheNode.SetValue("500mm");
只是为了澄清,只有当父母是“文本框”时才想更新“TextAlign”? – DaveShaw 2012-02-09 11:54:56
是的..我对检索和修改该特定元素感兴趣.... – user559142 2012-02-09 11:59:52
不应该“文本框”是“文本框”? – DaveShaw 2012-02-09 13:16:13