Check XML file for a given structure and edit it in case

Hey guys,

So I’ve an XML file for my Maps and stuff (using tiled).
I have this attribute in my XML File:

 <objectgroup name="objectLayer">
<!--- blabla --->
 </objectgroup>

Unfortunately Tiled is not generating this .XML file in the right format to be handled by my map creation process.
I need to add an ID and a height and width to this attribute, so the desired outcome would be:

 <objectgroup id="0" height="32" width="32" name="objectLayer">
<!--- blabla --->
 </objectgroup>

What would be the best way to first check whether the .XML attribute is correct and in case it’s not adding these three values to it?
I know there are some .XML libraries like SAX OR DOM but I’m not quite sure which one to take or whether these frameworks might be a little bit of overkill for my task.

Thanks!

I figured this out, thank you!
No clue if this is the smartest way tho:

public static void updateTMXforObjectLayer(String fileName) throws SAXException, IOException, ParserConfigurationException, TransformerException {
		DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
		
		Document doc = docBuilder.parse("src/main/resources/maps/"+fileName);
		NodeList list = doc.getElementsByTagName("objectgroup");
		if(list != null){
		
		Element el = null;
		for(int i = 0; i < list.getLength(); i++){
		el	= (Element) list.item(i);
		el.setAttribute("id", "1");
		el.setAttribute("height", "1");
		el.setAttribute("width", "1");
		}
		
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty(OutputKeys.METHOD, "xml");
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File("src/main/resources/maps/"+fileName));
		transformer.transform(source, result);
		}
	}