2017-01-16 1 views
0

모두 좋은 하루. 데이터베이스에 HTML 코드를 저장하려고하는데 SHEF(Swing HTML Editor Framework)을 사용하고 있지만 큰 문제가 있습니다. 일반적으로, 생성 된 HTML은 다음과 같이이다 :JSoup 또는 HTMLCleaner를 사용하여 HTML 코드를 단축하는 방법

<div> 
This is the first paragraph 
</div> 
<div> 
This is the second paragraph. 
</div> 
<div> 
This is the last paragraph. 
</div> 

내가 "깨끗한"HTML 코드 및 결과이 대신처럼 보이게하려면 :

<div> 
This is the first paragraph 
<br> 
This is the second paragraph. 
<br> 
This is the last paragraph. 
</div> 

내가 HTMLCleanerJSoup을 사용하려고하지만, 나는 그것을 만들지 않았다. 난 단지 JSoup이

<div> 
This is the first paragraph 
</div> 
<div> 

</div> 
<div> 
This is the last paragraph. 
</div> 

는이되도록 작동 할 수

<div> 
This is the first paragraph 
</div> 
<br> 
<div> 
This is the last paragraph. 
</div> 

이것은 내가 사용하는 JSoup 코드 :

Document source = Jsoup.parse(sourceString); 

// For each element 
for(Element el: source.select("*")) { 

    if(el.children().isEmpty() && !el.hasText() && el.isBlock()) { 
     el.replaceWith(new Element(Tag.valueOf("br"), ""));//replace empty tags with newline 
    } 
} 
return source.body().html(); 

짧은 생성 된 HTML 코드를 만들 수있는 방법이 있나요 ? 감사!

+2

HTML 청소/편집은 스윙과 관련이 없습니다. 앱 때문에 스윙 태그를 추가하지 마십시오. Swing API 중 일부를 사용합니다. –

답변

2

HTML을 사용하지 않고 최소화하려는 대신 gzip으로 압축 한 다음 대신 DB에 저장하는 것이 좋습니다.

CPU 오버 헤드가 최소화되고 절약 효과가 훨씬 커집니다. 그리고 귀하의 코드는 더 간단하고 더 일반적입니다. HTML 용 gzip은 일반적으로 75 % -80 %의 압축률을 제공하지만 일부 태그를 제거하면 10 %를 줄 것입니다.

다음 예는 compress/decompress입니다.

+0

그럴 수도 있지만 다른 기존 응용 프로그램에 영향을 미칩니다. / – triForce420