V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
zshneedmoney
V2EX  ›  程序员

请教大佬们一个关于 xml 同名节点保存进数据库的问题

  •  
  •   zshneedmoney · Mar 13, 2020 · 1797 views
    This topic created in 2244 days ago, the information mentioned may be changed or developed.

    有如下的 xml 结构

    <main>
    <version>1.0</version>
    <copyright>web</copyright>
    
    <article>
    	<field name="节点" dbfieldtype="0" id="vc_jd">1</field>
    	<field name="组配分类" dbfieldtype="0" id="vc_zpfl">2</field>
    </article>
    <article>
    	<field name="节点" dbfieldtype="0" id="vc_jd">3</field>
    	<field name="组配分类" dbfieldtype="0" id="vc_zpfl">4</field>
    </article>
    </main>
    

    我想讲 article 里的 field 存进库 目前的想法:

    1.先循环取值(selectNodes("main/article/field"),然后循环 nodes 根据 attributeValue("vc_jd")取到想要的节点)。

    2.使用 map 保存节点的 id 和节点内的 text 这样可以根据 id 取对应的值放进数据库

    3.导致的后果就是由于 id 一样 值会覆盖 导致 map 里只有{ vc_jd=3,vc_zpfl=4 }并不能把数据全部保存进库

    请大家提出宝贵建议 多谢!!

    2 replies    2020-03-14 13:18:38 +08:00
    vibbow
        1
    vibbow  
       Mar 14, 2020
    你需要一个自增 ID
    zshneedmoney
        2
    zshneedmoney  
    OP
       Mar 14, 2020
    结贴,在循环外定义 list 循环内创建 map 存进 list 即可,打扰了。自己昨天头脑不清醒。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3498 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 00:10 · PVG 08:10 · LAX 17:10 · JFK 20:10
    ♥ Do have faith in what you're doing.