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

前端 未结 30 2127
别那么骄傲
别那么骄傲 2020-11-22 02:54

I have a Java based web service client connected to Java web service (implemented on the Axis1 framework).

I am getting following exception in my log file:

30条回答
  •  春和景丽
    2020-11-22 03:41

    Actually in addition to Yuriy Zubarev's Post

    When you pass a nonexistent xml file to parser. For example you pass

    new File("C:/temp/abc")
    

    when only C:/temp/abc.xml file exists on your file system

    In either case

    builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    document = builder.parse(new File("C:/temp/abc"));
    

    or

    DOMParser parser = new DOMParser();
    parser.parse("file:C:/temp/abc");
    

    All give the same error message.

    Very disappointing bug, because the following trace

    javax.servlet.ServletException
        at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
    ...
    Caused by: org.xml.sax.SAXParseException: Content is not allowed in prolog.
    ... 40 more
    

    doesn't say anything about the fact of 'file name is incorrect' or 'such a file does not exist'. In my case I had absolutely correct xml file and had to spent 2 days to determine the real problem.

提交回复
热议问题