I'm using dom4j to parse XML files on line.
File file = new File("text.xml");
SAXReader reader = new SAXReader();
Document document = reader.read(file);
There is a syntax error in some XML files, which make the program throw SAXParseException: The prefix X for element X:A is not bound at line reader.read(file).
I know what the error is, and how to make the XML files right. Just as what said in this article
But the problem is the XML file is uploaded by users, I can not change the file before parse it, and I can not ask the user to change the XML file.
So, is there a way to parse the xml file with a undefined prefix error exist?
You could parse it with a DOM parser that isn't Namespace aware, but it will probably open up more problem areas than what you already have. The correct behavior is of course to validate the uploaded files and reject those that isn't correct XML or in any other way violate the contracts in place.
You do have the contracts in place, right?