I would like to write metadata to a PNG image that I create.
My understanding of Java Advanced Image API is that I should use IIOMetadata, but code snip
IIOMetadata
To add to other answer, you can also try the PNGJ library, it has full metadata support.
BTW, I don't understand what you are refering to with the "XML-like" structure of metadata.