Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何更改名称空间的前缀?_C#_.net_Xml_Powershell_Xml Parsing - Fatal编程技术网

C# 如何更改名称空间的前缀?

C# 如何更改名称空间的前缀?,c#,.net,xml,powershell,xml-parsing,C#,.net,Xml,Powershell,Xml Parsing,如何改变这一点 <d xmlns='uri' xmlns:a='uri'> <a:c/> <c a:atr=':a:b:c:d:e:f:'/> </d> 进入这个 <d xmlns='uri' xmlns:b='uri'> <b:c/> <c b:atr=':a:b:c:d:e:f:'/> </d> ? 有可能吗?最好使用System.Xml.XmlDocu

如何改变这一点

<d xmlns='uri' xmlns:a='uri'>
    <a:c/>
    <c a:atr=':a:b:c:d:e:f:'/>
</d>

进入这个

<d xmlns='uri' xmlns:b='uri'>
    <b:c/>
    <c b:atr=':a:b:c:d:e:f:'/>
</d>

?

有可能吗?最好使用
System.Xml.XmlDocument


如果.Net无法实现此功能,您知道它可以实现什么功能吗?

我对此API有点生疏,但您应该能够使用替换命名空间:

var document = XDocument.Load(@"E:\input.xml");

// Find and remove the namespace
document.Root.Attribute(XNamespace.Xmlns + "a").Remove();

// Add a new namespace with same uri and different prefix
document.Root.Add(new XAttribute(XNamespace.Xmlns + "b", "uri"));

document.Save(@"E:\output.xml");

保存时,
XDocument
会重新生成XML,只要您保持相同的uri,就应该应用新前缀。

我对该API有点生疏,但您应该能够使用替换命名空间:

var document = XDocument.Load(@"E:\input.xml");

// Find and remove the namespace
document.Root.Attribute(XNamespace.Xmlns + "a").Remove();

// Add a new namespace with same uri and different prefix
document.Root.Add(new XAttribute(XNamespace.Xmlns + "b", "uri"));

document.Save(@"E:\output.xml");

保存时,
XDocument
将重新生成XML,只要您保持相同的uri,就应该应用新前缀。

可能重复:可能重复:System.XML.XmlDocument是否可能?因为如果
xmlns
xmlns:a
相同,则每个没有前缀的节点都将以
b
作为前缀(如果
a
更改为
b
)。是否可以使用System.Xml.XmlDocument?因为如果
xmlns
xmlns:a
相同,每个没有前缀的节点都将以
b
作为前缀(如果
a
更改为
b
)。