如何在Java中使用DOM解析器存储xml节点名称及其对应的文本值?

时间:2018-09-23 05:23:46

标签: java xml dom xml-parsing

我以以下格式来自Web服务的xml响应。

<user-data>
<user>
<ID>1001</ID>
<what-is-your-address-choose-all-that-apply>A</what-is-your-address-choose-all-that-apply>
<what-is-your-address-choose-all-that-apply>B</what-is-your-address-choose-all-that-apply>
<what-is-your-address-choose-all-that-apply>C</what-is-your-address-choose-all-that-apply>
<What-are-your-areas-of-interest-choose-all-that-apply>Computer</What-are-your-areas-of-interest-choose-all-that-apply>
<What-are-your-areas-of-interest-choose-all-that-apply>IT</What-are-your-areas-of-interest-choose-all-that-apply>
</user>
</user-data>

使用DOM解析器和Jpa存储库,我可以将这些节点文本上下文成功保存为db中的内容:

user_id          field_value
1001              A
1001              B
1001              C
1001              Computer
1001              IT

但是我需要将值及其对应的节点名称一起存储:

user_id       field_name                                     field_value
1001     what-is-your-address-choose-all-that-apply            A
1001     what-is-your-address-choose-all-that-apply            B
1001     what-is-your-address-choose-all-that-apply            C
1001     What-are-your-areas-of-interest-choose-all-that-apply Computer
1001     What-are-your-areas-of-interest-choose-all-that-apply IT

那么我该如何做到这一点。谢谢。

0 个答案:

没有答案