Hi all,

I have a xml file, the structure as follows.

<?xml version="1.0"?>

<data>
<key>467</key>
<name>eranga262154</name>
</data>
I want to write extra tag as follows
<?xml version="1.0"?>

<data>
<key>467</key>
<name>eranga262154</name>
<id>123</id>
</data>
How can I do that. I'll try something like this, but it's not update my xml file.

Code:
            DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
            
            Document doc = docBuilder.parse (new File("records.xml"));
            
        // Try to add an additional node
            Node data = doc.getFirstChild();
            NamedNodeMap dataAttributes = data.getAttributes();
            Attr options = doc.createAttribute("id");
            options.setValue("123");
            dataAttributes.setNamedItem(options);