如何替换xml文件中的节点 [英] how to replace the nodes in xml file

查看:236
本文介绍了如何替换xml文件中的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有两个xml文件,比如...



一个是测试.xml



 <  政策 >  
< feesandtaxesbyproduct >
< feeandtaxes >
< < span class =code-leadattribute> feesandtaxesbystate >
.....
< / feesandtaxesbystate >

< span class =code-keyword>< feeandtaxesbystate >
.....
< / feesandtaxesbystate >
< ; feesandtaxesbystate >
.....
< span class =code-keyword>< / feesandtaxesbystate >
< feesandtaxesbystate >
.....
< / feesandtaxesbystate >


< / feeandtaxes >
< / feesandtaxesbyproduct >
< / policy >
< / data >


第二个XML是test2.xml

< feesandtaxesbyproduct < span class =code-keyword>>

< feeandtaxes >
< feesandtaxesbystate > ;
.....
< / feesandtaxesbystate >

< feeandtaxesbystate >
.....
< / feesandtaxesbystate >
< feesandtaxesbystate >
.....
< / feesandtaxesbystate >
< feesandtaxesbystate >
.....
< / feesandtaxesbystate >


< / feeandtaxes >
< / feesandtaxesbyproduct >


现在我必须从第二个xml中获取feeandtax整个节点并在第一个xml中替换....

请建议。

解决方案

检查这两个选项。会给你一个提示。



http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.replacechild(v = vs.110)的.aspx [<一个href =http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.replacechild(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]

http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.replacewith(v = vs.110).aspx [ ^ ]


查看 XmlDocument 类可用的 ImportNode 方法。

Hi,

I have two xml file like...

One is "test.xml"

<policy>
        <feesandtaxesbyproduct>
            <feeandtaxes>
                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>

                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>
                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>
                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>


            </feeandtaxes>
        </feesandtaxesbyproduct>
    </policy>
</data>


second XML is "test2.xml"

        <feesandtaxesbyproduct>
            <feeandtaxes>
                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>

                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>
                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>
                <feesandtaxesbystate>
                .....
                </feesandtaxesbystate>


            </feeandtaxes>
        </feesandtaxesbyproduct>


Now i have to take the feesandtaxes entire node from second xml and replace in first xml....

Please suggest.

解决方案

Check this two options. Will give you a hint.

http://msdn.microsoft.com/en-us/library/system.xml.xmlnode.replacechild(v=vs.110).aspx[^]
http://msdn.microsoft.com/en-us/library/system.xml.linq.xelement.replacewith(v=vs.110).aspx[^]


Take a look at ImportNode method available with XmlDocument class.


这篇关于如何替换xml文件中的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆