I can not do insert before tag "</catalog>"
You don't provide enough information, so this is a shoot in the dark. Are you aware that it is not usually possible to directly modify the contents an ordinary sequential file (except appending new contents at the end). But there are some ways to work around that limitation.
One of the common ways to modify a file is to read it into memory, to modify the contents in memory, and to write back the modified contents into the file (i.e. clobbering the existing content). Usually, you would first rename the original file or use a temporary file for writing, and do the necessary house-cleaning afterwards, once you have confirmed that everything went well, just to make sure you don't accidentally delete your original data.