0
IMG 태그의 텍스트와 src 속성을 모두 업데이트해야하는 HTML 문서가 있습니다. 나는 자바에서 일하고있다. HTML에서 다음 문자열을 대체하려고합니다. DataName, DataText 및 DataIcon. Java의 IMG 태그에서 src 속성 바꾸기
내가 문자열 DataName 및 DataText을 대체 할 suceeded 있지만
<body>
<h1 align="center">DataName</h1>
<div class="tabber">
<div class="tabbertab">
<h2>Info</h2>
<p>DataText</p>
</div>
<div class="tabbertab">
<h2>Pictures</h2>
<div id="album">
<ul class="gallery">
<li><a href="#nogo" tabindex="1">1<img src=DataIcon alt="landscape image 1" title="landscape image 1" /></a></li>
<li><a href="#nogo" tabindex="1">2<img src="C:\thesis\100GreatP\eclipse_ws\test\data\pictures\1\pyramid2.jpg" alt="landscape image 2" title="landscape image 2" /></a></li>
</ul>
</div>
</div>
<div class="tabbertab">
<h2>Video</h2>
</div>
</div>
, 나는 문자열로 데이터베이스에 저장 내 이미지 URL에 의해 DataIcon를 교체 성공 havent 한. 디버그를 검사하면 DataIcon 문자열을 검색하지 못한다는 의미입니다. 클래스는
NodeList nl = new NodeList();
String htmlString = null;
InputStream contentStream = null;
String textString = null;
String resultStr = getDatabaseAttribute(name,"DESCRIPTION");
String resultStr2 = getDatabaseAttribute(name,"NAME");
String resultStr3 = getDatabaseAttribute(name,"ICON_path");
try
{
// Read the URL content into a String using the default encoding (UTF-8).
contentStream = WWIO.openFileOrResourceStream(BROWSER_BALLOON, this.getClass());
htmlString = WWIO.readStreamToString(contentStream, null);
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
WWIO.closeStream(contentStream, resultStr);
}
try {
Parser parser = new Parser(htmlString);
nl = parser.parse(null);
nl.visitAllNodesWith(new MyNodeVisitor(resultStr3, resultStr2,resultStr));
nl.toString();
} catch (ParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String output = nl.toHtml();
return output;
아무도 도와 줄 수 같은 방법으로 내 응용 프로그램 코드에 적용되었습니다
public class MyNodeVisitor extends NodeVisitor {
String name;
String text;
String icon;
public MyNodeVisitor() {
}
public MyNodeVisitor(String IconPath, String Name, String Text){
this.name = Name;
this.text = Text;
this.icon = IconPath;
}
public void visitStringNode (Text string)
{
if (string.getText().equals("DataName")) {
string.setText(name);
}
else if(string.getText().equals("DataIcon")){
string.setText(icon);
}
else if (string.getText().equals("DataText")){
string.setText(text);
}
}
}
: 문제를 적용하는 나는 HTMLparser를 사용하고 난 다음 클래스를 작성했습니다? 모든 문제는 IMG 태그에서 DataIcon 문자열을 검색하지 못한다는 것입니다. 당신의 도움을 주셔서 감사합니다.
감사합니다! 처음부터 if 문은 if (Tag isinstanceof ImageTag)입니다. 그러나, 당신은 나를 많이 도와 줬어, 고마워! – MichalB