如何使用c#将节点值传递给xml中的父节点 [英] How to transfer node value to parent node in xml using c#
问题描述
Hello All,
Hello All,
请帮助我实现这一目标。我在c#中操作xml文档。这里我需要将内部元素值转换为上部元素值。即
Please help me to achieve this. I am manipulating xml document in c#. Here i need to transform inner element value to upper element value. i.e
我的输入如下
< AttributeValue>
< AttributeStringValue>
< StringValue> CVC-CR< / StringValue>
< / AttributeStringValue>
< / AttributeValue>
我的输出应该如下所示
< AttributeValue>
< AttributeStringValue>
CVC-CR
< / AttributeStringValue>
< / AttributeValue>
请帮我在c#中实现这个目标
please help me to achieve this in c#
谢谢
Chandu
Chandu
推荐答案
你好Chandu,
Hello Chandu,
有一个方式替换节点使用 XDocument ,请尝试。
There is a way replace nodes in using XDocument , please try it.
XDocument xd = XDocument.Parse("<AttributeValue><AttributeStringValue><StringValue> CVC - CR </StringValue></AttributeStringValue></AttributeValue>");
string replaceValue = xd.Descendants("StringValue").First().Value;
xd.Root.Descendants("StringValue").FirstOrDefault().ReplaceWith(replaceValue);
xd.Save("XMLFile1.xml");
此致,
Neil Hu
这篇关于如何使用c#将节点值传递给xml中的父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!