1

I know there are a few SAXParser questions there, but I can't find one that describes my problem:

I have a String containing XML data, and I am passing it to a ByteArrayInputStream:

public boolean parse(String message) {
        ByteArrayInputStream bis = new ByteArrayInputStream(message.getBytes());

and I call the parse method on it

saxparser.parse(bis, handler); //this row throws a FileNotFoundException

Despite not mentioning any files, the parsing throws a FileNotFoundException. Weirdly enough, it's trying to find a filename in my workspace that doesn't exist and later I found that the filename is part of a string enclosed by double quotes (see below, let's call it the "theFile.extension" file)

EDIT: I thought maybe my XML is wrongly written for some reason:

<?xml version="1.0"?>
<!DOCTYPE presence PUBLIC "Some-valid-stuff" "theFile.extension">

Where should I look for a solution in this case?

Thanks

2
  • 1
    DOCTYPE x PUBLIC "..." "location" tries to find a file at your (local) "location". Apparently you don't have it. Commented Oct 27, 2015 at 18:03
  • 1
    The SAX parser is trying to validate the xml using the specified file. I don't remember now but there is a way to disable the validation Commented Oct 27, 2015 at 18:13

1 Answer 1

4

The SAX parser is trying to validate the xml using the specified DTD file, and that's the reason it's trying to load that file.

You can disable the validation as below.

saxParserFactory.setValidating(false)
saxParserFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
Sign up to request clarification or add additional context in comments.

2 Comments

This worked like a charm. I unfortunately don't know how I would've been able to figure this out from the API. Do you think I missed anything, or just that experience is needed? Many thanks
Maybe bit of both :). The exception said it was looking for the file mentioned in DOCTYPE & if you know the purpose of that file, i.e. validation, then may be you could have looked for method relating to validation in the parser api.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.