您可以简单地根据当前节点名称设置节点名称。在下面的示例中,我使用了一个字典来替换节点名称。
您可以使用您拥有的任何其他逻辑来替换节点名称,就像在原始到新的映射中一样。
XDocument doc = XDocument.Parse(@"<SequenceFlow>
<FlowWriteLine> hiiii </FlowWriteLine>
<NotToBeReplaced>byeee</NotToBeReplaced>
</SequenceFlow> ");
Dictionary<string, string> replacements = new Dictionary<string, string>() { { "SequenceFlow", "Workflow" }, { "FlowWriteLine", "WriteLine" } };
foreach (XElement child in doc.Root.DescendantsAndSelf())
{
string replacementValue = string.Empty;
if (replacements.TryGetValue(child.Name.LocalName, out replacementValue))
{
child.Name = replacementValue;
}
}
以上给出的输出为
<Workflow>
<WriteLine> hiiii </WriteLine>
<NotToBeReplaced>byeee</NotToBeReplaced>
</Workflow>