자바 프로그램 중인데 도와주세요....

kirina70의 이미지

try{
	StringTokenizer stk;
	PrintWriter out = new PrintWriter(new FileWriter( outputFile, true ));
	PrintWriter out_xml = new PrintWriter(new FileWriter( outxmlFile, true ));
 
	out.println(title + "\t" + author + "\t" + price + "\t" + url);
 
	out_xml.println("<album_info>");
        title = title.replaceAll("<" , "&lt;").replaceAll(">" , "&gt;").replaceAll("&","&amp;").replaceAll("\"" , "&quot;").replaceAll("'" , "&#039;") ;
	out_xml.println("<album>"+title+"</album>");
 
 
        author = author.replaceAll("<" , "&lt;").replaceAll(">" , "&gt;").replaceAll("&","&amp;").replaceAll("\"" ,
	out_xml.println("<singer>"+author+"</singer>");
 
	out_xml.println("<price>"+price+"</price>");
	out_xml.println("</album_info>");
 
	out.flush();
	out.close();
 
	out_xml.flush();
	out_xml.close();
 
}catch(Exception e){
	System.out.println("print error");
}

-----hanbak님께서 알려주신대로(고맙습니다.) 해도 같은 문제가 생긱네요
-----하튼 코드는 hanbak님께서 알려주신대로 수정했습니다. 제가 아직 초보라 위의 코드가 이상하게 나올지는 모르나 hanbak님께서 알려주신대로 고쳤습니다.

문제는

당근 자바로 작성했고 근데 문제점이

저렇게 자동으로 대략 10000개 정도의 데이터를 쓰게 됩니다.

근데 잘 나가다가

예를 들어서

1699 줄에 album_info> (원래는 ) 이런식으로 글자가 짤려나오거나

2034 줄에

(원래는 그냥 ) 이런식으로 원하지도 않는 글자가 첨부되는 현상이 계속 생깁니다.

xml문법이나 이런 것에 잘못된것은 없구요....

그냥 자바에서 xml문서를 이상하게 써주고 있습니다...........(글자를 짤라 먹거나 아니면 자기맘대로 붙이거나)

답변부탁드립니다.

june의 이미지

이상하게 짤려 나오는 xml을 보여주세요.
개행문자가 들어있다던가... 그럴수 있죠.
해당하는 문자를 char형으로 디버깅하면 될듯한데요.

제목에는 해당문제를 간략히 적으시면 더 많은 분들이 보시리라 봅니다.^^
==============
커피는 블랙이나 설탕만..

커피는 블랙이나 설탕만..

hanbak의 이미지

xml에서 인식하는 특수문자들을 변환하시려면..

<  &amp;lt;
>  &amp;gt;
&  &amp;amp;
"  &amp;quot;
'  &amp;&#35;039;

요것들도 해 주셔야 합니다.

jdk가1.4 이상이시라면 tokenizer 를 쓰지 마시고

 title = title.replaceAll("<" , "&amp;lt;").replaceAll(">" , "&amp;gt;").replaceAll("&","&amp;amp;").replaceAll("\"" , "&amp;quot;").replaceAll("'" , "&amp;&#35;039;") ;
 author = author.replaceAll("<" , "&amp;lt;").replaceAll(">" , "&amp;gt;").replaceAll("&","&amp;amp;").replaceAll("\"" , "&amp;quot;").replaceAll("'" , "&amp;&#35;039;") ;

요렇게 사용하시는게 ?

kirina70의 이미지

june님께서 요청하셔서 다음과 같이 보여드립니다.
원래 data.txt라는 곳에 한번 쓰고
똑같은 것을 XML로 표현하는 프로그램입니다.
data.txt에는 제대로 표현되는데
XML에는 제대로 표현이 안되서 참 지금 고민입니다. 왜 그런지....

이것은 원래의 데이터 입니다. 앨범 이름 / 가수 이름 / 값 이렇게 나옵니다.
------------------------------------------------------------------------------------------------
김목경 - Live In Concert 김목경 91100
봄여름가을겨울 - Iamssawdizz Live 05 봄여름가을겨울 91800
리플레이 (Replay) - 1집 - 그래도 살아야죠 리플레이 (Replay) 61300
김원중 3집 - 꿈꾸는 사람만이 세상을 가질수 있지 [재발매] 김원중 61300
스맥스(Smax) - A S'Max Birth! 스맥스 (Smax) 81200
------------------------------------------------------------------------------------------------

그리고 이것은 이것을 XML로 찍었을 때의 일입니다.
<>이런식으로 할라니까 화면에 아무것도 안보여서
< -> " > -> " 이렇게 바꾸었습니다.
즉 따옴표를 다 중괄호로 생각하시면 될듯......
문법은 대략 맞는데 저렇게 미완성 된 문장이나 쓸데 없는 문장이 쓰여져서 나는 오류입니다.

"album_info"
"album" 김목경 - Live In Concert "/album"
"singer" 김목경 "/singer"
"price" 91100 "/price"
"/album_info"

e" 41200 "/price" ----------->없는 데이터가 찍혔습니다.(여기서 에러)
"/album_info" -----------> 없는 데이터가 찍혔습니다.(여기서 또 에러)

"album_info"
"album" 봄여름가을겨울 - Iamssawdizz Live 05 "/album"
"singer" 봄여름가을겨울 "/singer"
"price" 91800 "/price"
"/album_info"

_info" ------------------------------------>안나와야 하는데 그냥 이렇게 프린트 되어 버렸습니다.(여기서 또 에러)

"album_info"
"album" 김원중 3집 - 꿈꾸는 사람만이 세상을 가질수 있지 [재발매]
"singer" 김원중 "/singer"
"price" 61300 "/price"
"/album_info"

읽어주셔서 감사합니다.

근데 혹 쓰는 버퍼를 완전히 지우지 않아서 그런거 같기도 한데

out_xml.flush()로도 잘 안 지워집니까??

완전히 날려버리는건 어찌 해야 하는지..... ㅠ.ㅠ

대략 1000줄 당 한 3개씩 나오네요.... 전체가 16000줄 정도 되는데

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.