Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


BOM?  org.xml.sax.SAXParseException: Content is not allowed in prolog.

Posted on 2006-08-24
Medium Priority
Last Modified: 2012-06-27
I read in a SOAP http response which is an xml string and try to build a DOM object out of it for parsing but I think a BOM (byte order mark) is causiing this exception...

2006-08-24 18:21:28,894 INFO  [STDOUT] Exception: Content is not allowed in prolog.
2006-08-24 18:21:28,904 INFO  [STDOUT] org.xml.sax.SAXParseException: Content is not allowed in prolog.
2006-08-24 18:21:28,904 INFO  [STDOUT]       at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
2006-08-24 18:21:28,904 INFO  [STDOUT]       at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
2006-08-24 18:21:28,904 INFO  [STDOUT]       at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

I googled around for a solution but no success? Anyone now how to strip away a BOM?

Question by:defa0009
  • 2
LVL 86

Accepted Solution

CEHJ earned 180 total points
ID: 17387139
Try something like:

try {
      PushbackReader r = new PushbackReader(new InputStreamReader(new URL(url).openStream()));
      int ch = -1;
      // scan for the < character
      while((ch = r.read()) != '<');
      if( ch == '<')
            r.unread('<') ;
      builder.parse(new InputSource(r));
} catch (Exception e) {

Author Comment

ID: 17388717
LVL 86

Expert Comment

ID: 17388772

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question