Here's my problem:
My program is getting XML files as its input. These files may or may not have an xml declaration, doctype declaration, or entity declaration, but they all conform to the same schema. When my program gets a new file, it needs to inspect it, and make sure it has declarations like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE my.doctype [
<!ENTITY % entity_file SYSTEM "my.entities.ent">
%entity_file;
]>
If it has that, it's great, and I can leave them as is, but if the declarations are missing or wrong, I need remove whatever is already there and add the correct declarations.
How can I do this (preferably easily, using standard Java 6 and/or Apache libraries)?