java 에서 xml 파싱할 때 에러

exsider의 이미지

Java 에서 apache 의 xerces 파서를 이용해 xml을 분석하는 프로그램을
만들고 있습니다.

그런데 실행시켜보면 parse() 메소드에서 다음과 같은 예외가 발생합니다.

Quote:
[Fatal Error] test.xml:4:6: The processing instruction target matching "[xX][mM][lL]" is not allowed.

에러가 부분은 이렇습니다.

Quote:
<?xml:stylesheet type="text/xsl" href="memo.xsl"?>

제가 보기에는 아무 문제가 없는 부분인데 여기서 에러가 납니다.
위줄을 주석처리하면 정상적으로 동작합니다.

org.apache.xerces.parsers.DOMParser 와
org.apache.xerces.parsers.SAXParser 를
모두 써 봤는데 모두 동일한 에러가 발생합니다.

SAXParser 쓸 때는 ErrorHandler 를 등록해서 예외를 무시하도록
만들었는데 해당 메소드( fatarerror() )는 호출되는데 역시 예외가
발생하며 비정상 종료됩니다.

뭐가 문제인가요???

M.W.Park의 이미지

exsider wrote:
Quote:
<?xml:stylesheet type="text/xsl" href="memo.xsl"?>

좀 바빠서... 테스트는 못해보고요...
대충 기억을 더듬어 보면, 다음과 같이 고치면 될것같습니다.

<?xml-stylesheet type="text/xsl" href="memo.xsl"?>

W3C draft에선 <?xml:stylesheet ...> 형식도 가능했던 것같습니다.
recommendation에선 <?xml-stylesheet ...> 형식으로 통일... 8)

-----
오늘 의 취미는 끝없는, 끝없는 인내다. 1973 法頂

exsider의 이미지

Quote:
W3C draft에선 <?xml:stylesheet ...> 형식도 가능했던 것같습니다.
recommendation에선 <?xml-stylesheet ...> 형식으로 통일...

그러면 테스트용으로 사용한 xml 파일이 올바른 형식이 아니었나 보네요.
제가 보고있는 xml 책에도 xml-stylesheet 로 되어있네요.

단 이문제를 비껴갈 수 있는 방법은 알아냈는데요,
파서 객체를 만든다음에 그 객체에
setFeature("http://xml.org/sax/features/namespaces",false);
메소드를 호출하니 위부분을 그냥 넘어가더군요.
이렇게 하는게 올바른 건지는 모르겠습니다.

atie의 이미지

Quote:

단 이문제를 비껴갈 수 있는 방법은 알아냈는데요,
파서 객체를 만든다음에 그 객체에
setFeature("http://xml.org/sax/features/namespaces",false);
메소드를 호출하니 위부분을 그냥 넘어가더군요.
이렇게 하는게 올바른 건지는 모르겠습니다.

올바른 방법이 아닙니다. xml namespace가 제대로 정의되지 않아서 생기는 에러인데, 위와 같이 namespace feature를 false로 하게 되면 namespace에 대한 processing을 하지 않으니 에러가 나지 않는거죠... test.xml과 memo.xsl의 namespace 부분을 다시 살펴 보세요.

----
I paint objects as I think them, not as I see them.
atie's minipage

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.