Skip to main content

org.xml.sax.SAXParseException: Reference is not allowed in prolog

1 reply [Last post]
shivram13
Offline
Joined: 2007-03-28

Hi,

I have been using DocumentBuilder to parse an xml string in our application but now came up with this exception:

org.xml.sax.SAXParseException: Reference is not allowed in prolog

When I looked at the xml data, I found that it does not have a prolog in it. I also found that the data contains end of line character ""
""
" in it.

This the xml to be parsed: (Qutoted them to view the unicodes in xml)

"
Test metadata
en
Blah
BEGIN:vcard

FN:Jan Austin

ORG:IBalahblahLtd

EMAIL:gg@gg.com

END:vcard
text/html
http://gg.com/
Medicine and Dentistry
"

And in the class, I used,

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(file);

I can not change the xml data to be parsed as the application gets this data from other targets through a web service.

So, can anyone please provide any suggestions to solve this issue please?

Thanks,
Shiv.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
spericas
Offline
Joined: 2003-06-10

Looking at the parser's source code, it can only report this error if it finds a "&" in the prolog. So somehow the error message does not correspond to the XML document that you posted. Are you certain that is the correct XML document? Do you always get the exact same error message? I've seen similar errors in the presence of race conditions too.