本文介绍了如何删除命名空间前缀.(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
我有一个 XElement,它是由如下所示的转换产生的.
I have an XElement, resulting from a transform that looks like the following.
<src:Person xmlns:src="http://www.palantir.za">
<src:Name>Jenifer Harvey</src:Name>
<src:BirthDate>1969-11-13</src:BirthDate>
<src:IdentityNumber>6906678550017</src:IdentityNumber>
<src:Sex>Male</src:Sex>
</src:Person>
我想将此 XElement 转换为一个新的 XElement,该 XElement 具有src"作为默认命名空间,而不是上面的命名"命名空间.
I would like to transform this XElement into a new XElement that has 'src' as a default namespace rather than a 'named' namespace as above.
我意识到它们可能在语义上是相同的,我只是想保持存储内容的一致性.
I realise they are probably semantically identical, I just want to maintain consistency in what is being stored.
我想要以下.
<Person xmlns="http://www.palantir.za">
<Name>Jenifer Harvey</Name>
<BirthDate>1969-11-13</BirthDate>
<IdentityNumber>6906678550017</IdentityNumber>
<Sex>Male</Sex>
</Person>
谢谢
问候
克雷格.
推荐答案
只需删除 xmlns:src 属性并添加一个新的 xmlns 属性:
Simply remove the xmlns:src attribute and add a new xmlns attribute:
XDocument xdoc = XDocument.Parse(
"<src:Person xmlns:src="http://www.palantir.za">" +
" <src:Name>Jenifer Harvey</src:Name>" +
" <src:BirthDate>1969-11-13</src:BirthDate>" +
" <src:IdentityNumber>6906678550017</src:IdentityNumber>" +
" <src:Sex>Male</src:Sex>" +
"</src:Person>");
xdoc.Root.Add(new XAttribute("xmlns", "http://www.palantir.za"));
xdoc.Root.Attributes(XNamespace.Xmlns + "scr").Remove();
这篇关于如何删除命名空间前缀.(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)