There is a separate dtd file for each of the XML files I need to read, but I do know which dtd file goes with which XML file, so that could work. What do you mean by appending the line before giving the file to the parser? Do you mean to modify the XML file in some way, or to feed the !DOCTYPE line to the parser first and then give the xml file to the parser, or something else? Would it work to call the parser's function that takes a string with the !DOCTYPE line and then call the parser's function that takes a file handle with the XML file? Would the parser apply the dtd file declarations to the XML file if I made these two calls?