0

I have an XML Document which contains XML elements containing attributes from which I would like to get it's value and store it in a Hashmap.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<Nodes>
    <Node name="test1">
        <mou>
            <line3>hello</line3>
        </mou>
    </Node>

    <Node name="test2">
        <mou>
            <line3>hello</line3>
        </mou>
    </Node>

    <InputNode name="Chance">
        <Test>
            <RoundTo>100</RoundTo>
        </Test>
    </InputNode>
    <InputNode name="total" />
</Nodes>

I'd like to parse this xml and retrieve the values attributes from all the elements named 'Node' and store it in a map object. So from the example above I would get

[name=test1,name=test2]

The problem is with maps the keys must be unique. How can I accomplish my goal using Java?

Moonie Asemani
  • 375
  • 1
  • 4
  • 13

1 Answers1

0

Sorry, I got your question wrong. You can parse the xml already. You want to store it in a map. You can create objects out of all the nodes. Node { nodeName, attribute1, attribute2} then you can save it as a map by {key,value} = {name, nodeObj}