java 替换src_替换Java中IMG标签的src属性

我有一个HTML文档,我需要更新IMG标签的text和src属性。我在Java工作。我想替换HTML中的以下字符串:DataName,DataText和DataIcon。替换Java中IMG标签的src属性

DataName

Info

DataText

Pictures

Video

虽然我suceeded替换字符串数据名称和DataText,我还没有成功通过存储在数据库中的字符串我IMAGEURL更换DataIcon。检查调试说,它只是简单地不能搜索DataIcon字符串。我使用的HTMLParser,我已经写了下面的类应用问题:

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);

}

}

}

类已经在我的应用程序代码以这样的方式

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;

任何人可以帮助我得到了应用?整个问题是它无法在IMG标签中搜索DataIcon字符串。谢谢你的帮助。

2013-03-28

MichalB

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值