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

前端 未结 30 2128
别那么骄傲
别那么骄傲 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:45

    To fix the BOM issue on Unix / Linux systems:

    1. Check if there's an unwanted BOM character: hexdump -C myfile.xml | more An unwanted BOM character will appear at the start of the file as ...

    2. Alternatively, do file myfile.xml. A file with a BOM character will appear as: myfile.xml: XML 1.0 document text, UTF-8 Unicode (with BOM) text

    3. Fix a single file with: tail -c +4 myfile.xml > temp.xml && mv temp.xml myfile.xml

    4. Repeat 1 or 2 to check the file has been sanitised. Probably also sensible to do view myfile.xml to check contents have stayed.

    Here's a bash script to sanitise a whole folder of XML files:

    #!/usr/bin/env bash
    
    # This script is to sanitise XML files to remove any BOM characters
    
    has_bom() { head -c3 "$1" | LC_ALL=C grep -qe '\xef\xbb\xbf'; }
    
    for filename in *.xml ; do
      if has_bom ${filename}; then
        tail -c +4 ${filename} > temp.xml
        mv temp.xml ${filename}
      fi
    done
    
    

提交回复
热议问题