私は、HTML を組み込んだ Java World Wind ベースのアプリケーションに取り組んでいます。name、text_description、icon_link などの属性を持つすべての関心のある場所を含むデータベースがあります。私の目的は、地球上の別の関心のある場所をクリックするたびに、HTML のテキスト文字列を別の文字列に置き換えることです。したがって、HTML ドキュメントを解析し、キーワードを検索して、データベース内の適切な文字列に置き換える必要があります。キーワードの検索と適切な文字列への置換を担当するクラスを作成しました。
public class MyNodeVisitor extends NodeVisitor {
String name;
String text;
String icon;
public MyNodeVisitor() {
}
public MyNodeVisitor(String Name, String Text, String IconPath){
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("DataText")){
string.setText(text);
}
else if(string.getText().equals("DataIcon")){
string.setText(icon);
}
}
}
したがって、HTML では、データベースから呼び出されるテキスト文字列に置き換えたいテキスト文字列 DataName、DataText、および DataIcon を定義しました。
上記のクラスは、私のコードでは次のように使用されます。
NodeList nl = new NodeList();
String htmlString = null;
InputStream contentStream = null;
contentStream = WWIO.openFileOrResourceStream(BROWSER_BALLOON, this.getClass());
htmlString = WWIO.readStreamToString(contentStream, null);
try {
Parser parser = new Parser(htmlString);
nl = parser.parse(null);
nl.visitAllNodesWith(new MyNodeVisitor(resultStr2,textString,resultStr3));
nl.toString();
} catch (ParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String output = nl.toHtml();
return output;
ここで、resultStr2、textString、および resultStr3 は、HTML のキー文字列「DataName」、「DataText」、および「DataIcon」を置き換える文字列です。
問題は、最初の 2 つの文字列 DataName と DataText の置換は機能しますが (つまり、データベースの別の要素を呼び出すたびに、具体的な要素に適した名前とテキストを取得しています)、DataIcon では機能しません。 . デバッグによると、HTMl で DataIcon String を定義したにもかかわらず、次のように DataIcon String の検索に失敗するだけです。
<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>
何が問題なのかわからないので、あらゆる種類の助けに感謝します。ありがとう!