Translate

[JAVA] 문제없는 xml파일에서 The processing instruction target matching "[xX][mM][lL]" is not allowed. 에러가 발생할때..



Maven 공부중 예제와 똑같이 따라했는데 TEST부분에서 다음과 같은 에러가 발생했다.


-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.sonatype.mavenbook.weather.YahooParserTest
1    INFO  YahooParser  - create XML Reader
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.616 sec <<< FAILURE!
Running org.sonatype.mavenbook.weather.WeatherFormatterTest
454  INFO  YahooParser  - create XML Reader
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.009 sec <<< FAILURE!

Results :

Tests in error: 
  testParser(org.sonatype.mavenbook.weather.YahooParserTest): Error on line 2 of document  : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.
  testFormat(org.sonatype.mavenbook.weather.WeatherFormatterTest): Error on line 2 of document  : The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The processing instruction target matching "[xX][mM][lL]" is not allowed.

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0

[ERROR] There are test failures.








로그를 보면 XML에 문제가 있다는 말 같은데 에디터로 해당 XML을 열어봐도 크게 잘못된 부분을 느낄 수 없었다.


http://thedesignspace.net/MT2archives/000815.html#.VGlOaTd_uwc
구글 검색을 통해 위의 글을 읽어보고 '<?xml version="1.0"...?>' 부분을 주석처리 하니 정상적으로 되었는데..
그 다음에 주석을 해제했는데도 정상적으로 작동이 되었다.





원인

http://ko.wikipedia.org/wiki/%EB%B0%94%EC%9D%B4%ED%8A%B8_%EC%88%9C%EC%84%9C_%ED%91%9C%EC%8B%9D

위의 글을 읽고서 어떤 문제가 있었는지 확실히 알게 되었다.


윈도우에서의 많은 편집기는 UTF-8로 저장 시 해당 파일의 제일 앞부분에 BOM 을 붙여넣게 되는데 Linux, Unix 에서는 BOM을 사용하지 않는것이 보통이라서 일반 문자열로 인식하기에..

<?xml version="1.0"... ?>

의 앞부분에 BOM 문자열이 들어가니 XML 형식에 맞지 않아서 에러가 발생한 문제였다.



일반적으로 편집기에서 따로 보이지 않아서 잘 알수가 없고..
일부 유닉스(아마 AIX로 기억..)에서 vi로는 보이지 않지만 cat으로 파일을 열었을 때 <?xml 앞에 깨진 글자가 있는 것을 본적이 있었다.





해결방법

Hex 편집이 가능한 편집기로 보면 앞부분에 이상한 문자열이 있는 것을 볼 수 있으며 해당 문자열(BOM)을 지우는 방법이 있고, 내가 사용하는 툴 처럼 해당 문서를 편집 후 저장하면 BOM을 지워주는 툴을 사용하면 편리하다. (사용툴: Ubuntu + IntelliJ 13.1 Ultimate)


댓글