0

Let's say I have the following XML document:

<Offices>
  <Office name="P">
    <Counter>1000</Counter>
  </Office>
  <Office name="K">
    <Counter>1006</Counter>
  </Office>
</Offices>

With that document I need to perform the following in Java:

  1. Parse the XML.
  2. Get the value of Counter given a certain value for a name attribute.
  3. Update the XML with a new value for Counter for exactly this Office.

For 2. I have considered using XPath but editing/updating the XML seems to be not that easy this way.

How could I go through the XML finding a certain office name and update its counter? The XML itself won't be large, only something like 20 office entries max.

Robert Strauch
  • 12,055
  • 24
  • 120
  • 192

1 Answers1

1

You can try looking at this answer: https://stackoverflow.com/a/5059411/1571550

It seems pretty straightforward and generic solution.

Community
  • 1
  • 1
MMendes
  • 84
  • 5