Writing in the middle of a xml file

I have a file named example.xml

I want to know how to write to the 3rd line on this file? What function to use?

I want to be able to write to this xml file right after the <sitemapindex xmlns=“http://www.sitemaps.org/schemas/sitemap/0.9”> tag.

Please someone tell me how?

Much appreciated.

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">