关于xml标签值更改 [英] regarding xml tags value change

查看:74
本文介绍了关于xml标签值更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在更新xml标签时遇到问题.

i have problem while updating xml tags.

<config>
  
  <keyinfo>
    <old_keys>
  
    </old_keys>
    <new_keys>
          <key id="1" name="Nocdesk" creationdate="" startdate="" enddate="" status="1">
        <oid id="1.1.9.3" startdate="" enddate="" status="1" value="15" />
        <oid id="1.1.9.3.3" startdate="" enddate="" status="1" value="" />
        <oid id="1.1.9.3.6" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.5.1" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.5.2" startdate="" enddate="" status="1" value="15" />
        <oid id="1.1.9.5.3" startdate="" enddate="" status="1" value="5" />
        <oid id="1.1.9.10" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.11" startdate="" enddate="" status="1" value="1" />
      </key>
    </new_keys>
  </keyinfo>
</config>



我的xml的类型.
我获得新的密钥ID,然后我希望此key_id = 1移至旧密钥,而新密钥获得key_id = 2的新密钥.

和xml变成这样...



that type of my xml.
i get new key id then i want this key_id = 1 is move to old key and new key gets new key with key_id =2.

and xml becomes like this...

<config>
  
  <keyinfo>
    <old_keys>
   <key id="1" name="Nocdesk" creationdate="" startdate="" enddate="" status="1">
        <oid id="1.1.9.3" startdate="" enddate="" status="1" value="15" />
        <oid id="1.1.9.3.3" startdate="" enddate="" status="1" value="" />
        <oid id="1.1.9.3.6" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.5.1" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.5.2" startdate="" enddate="" status="1" value="15" />
        <oid id="1.1.9.5.3" startdate="" enddate="" status="1" value="5" />
        <oid id="1.1.9.10" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.11" startdate="" enddate="" status="1" value="1" />
      </key>
    </old_keys>
    <new_keys>
          <key id="2" name="Nocdesk" creationdate="" startdate="" enddate="" status="1">
        <oid id="1.1.9.3" startdate="" enddate="" status="1" value="15" />
        <oid id="1.1.9.3.3" startdate="" enddate="" status="1" value="" />
        <oid id="1.1.9.3.6" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.5.1" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.5.2" startdate="" enddate="" status="1" value="15" />
        <oid id="1.1.9.5.3" startdate="" enddate="" status="1" value="5" />
        <oid id="1.1.9.10" startdate="" enddate="" status="1" value="1" />
        <oid id="1.1.9.11" startdate="" enddate="" status="1" value="1" />
      </key>
    </new_keys>
  </keyinfo>
</config>



如果有解决方案,请给我C#的代码.net



if any one have solution then please give me code for C# .net

推荐答案

我将只为您指出一种实现方法.当然,有多种方法可以实现这一目标:

您应该做的是:
-找到要移至旧键"节点的节点.通过使用 XmlNode.CloneNode方法 [ ^ ]将其添加到OldKeys节点,然后删除从NewKeys复制的节点(为此,您必须再次搜索该节点).

-找到NewKeys节点并执行删除过程后,将所需的新节点数据插入到New Keys节点中.

如果您选中此链接 [ ^ ]它为您进行总结,您会发现完成它所需的大多数方法.

祝你好运.
I will just point you just one way how to do it. Of course there will be multiple ways to accomplish that:

What you should do is:
-Find the node that you want to move to OldKeys node. By using XmlNode.CloneNode Method[^] add it to OldKeys node and delete the node that you copied from NewKeys (to do that you have to search for the node again).

-After find the NewKeys node and the deletion process, insert the new node data you desired to New Keys node.

If you check this link[^] it sums it up for you and you will find most of the methods you need to accomplish it.

Good luck.


这篇关于关于xml标签值更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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