这让我发疯,我已经尝试了 2 天了。
我基本上想根据名称替换值。
我有如下的xml:
<session>
<immediate>
<diff name="TEST_DIFF">
<pivot name="(Original)">
<grid-processor name="mdStoredShape"/>
<axes>
<axis position="SLICERS">
<attribute name="Result Namespace" mode="INCLUSIVE">
<selection value="$NAMESPACE$"/>
</attribute>
<attribute name="Date" mode="INCLUSIVE">
<selection value="$DATEFROM$"/>
</attribute>
<attribute name="Book" mode="INCLUSIVE">
<selection value="$BOOK_NAME$" type="Book Hierarchy"/>
</attribute>
<attribute name="Measure" mode="INCLUSIVE">
<exclude value="PV"/>
</attribute>
<attribute name="Risk Source System" mode="INCLUSIVE">
<selection value="gdsldn"/>
</attribute>
<attribute name="Is Error">
<selection value="false"/>
</attribute>
</axis>
<axis position="DISCRIMINATOR">
<attribute name="Book" mode="ALL"/>
<attribute name="Book" mode="ALL"/>
<attribute name="Measure" mode="ALL"/>
</axis>
<axis position="RESULT">
<attribute name="SUM(Money Value In(GBP))"/>
<attribute name="COUNT_DISTINCT(Book)"/>
</axis>
</axes>
</pivot>
<pivot name="(New)">
<grid-processor name="mdStoredShape"/>
<axes>
<axis position="SLICERS">
<attribute name="Result Namespace" mode="INCLUSIVE">
<selection ref="$NAMESPACE$"/>
</attribute>
<attribute name="Date" mode="INCLUSIVE">
<selection ref="$DATETO$"/>
</attribute>
<attribute name="Book" mode="INCLUSIVE">
<selection value="$BOOK_NAME$" type="Book Hierarchy"/>
</attribute>
<attribute name="Measure" mode="INCLUSIVE">
<exclude ref="PV"/>
</attribute>
<attribute name="Risk Source System" mode="INCLUSIVE">
<selection value="gdsldn"/>
</attribute>
<attribute name="Is Error">
<selection value="false"/>
</attribute>
</axis>
<axis position="DISCRIMINATOR">
<attribute name="Book" mode="ALL"/>
<attribute name="Book" mode="ALL"/>
<attribute name="Measure" mode="ALL"/>
</axis>
<axis position="RESULT">
<attribute name="SUM(Money Value In(GBP))"/>
<attribute name="COUNT_DISTINCT(Book)"/>
</axis>
</axes>
<source name="risk"/>
</pivot>
</diff>
</immediate>
</session>
我想用实际值替换所有 $NAMESPACE$ 值。
有人可以帮忙吗?
有关我正在使用的其他信息
XElement xeNS = Xdoc.Descendants("selection").First(el => (String)el.Attribute("value").Value == "$NAMESPACE$");
xeNS.SetAttributeValue("value", ns);
但这仅取代了第一个实例。我希望 linq 查询然后循环并应用更改?