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.

1 Answer 1

1

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

It seems pretty straightforward and generic solution.

Sign up to request clarification or add additional context in comments.

1 Comment

I like the JAXB approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.