对java HTML解析器/编辑器的建议 [英] recommendations for a java HTML parser/editor

查看:71
本文介绍了对java HTML解析器/编辑器的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用第三方HTML编辑器来做什么(我希望)是一个简单的操作时,我遇到了问题。由于这些问题,我正在寻找可用于执行操作的替代HTML解析器的建议。



这是我的情况,我的html中有span标记(使用ID属性来标识它们),我只是想根据客户端另一个区域中的更新来替换它们的内容。例如:

 < html> 
< body>
< p> Hello< span id =1>名称< / span>您是< / body>
< / html>

我一直在尝试使用 HTMLDocument class in javax.swing.text 像这样:

 元素e ; 
e = doc.getElement(document.getDefaultRootElement(),Attribute.ID,1);
document.setInnerHTML(element,John);
e = doc.getElement(document.getDefaultRootElement(),Attribute.ID,2);
document.setInnerHTML(element,99);

但返回的元素是一个叶元素,并且不允许设置innerHTML。不幸的是,文件,阅读器&解析器全部由第三方&所以我不能真正修改它。



那么,我希望的是,别人有类似的问题,并可以推荐一个替代库来做到这一点? 您真的不能用java.swing.text.HTMLDocument完成这项工作?



我从来没有尝试过这样做,但通过API阅读

  document.replace(e.getStartOffset(),e.​​getEndOffset() -  e.getStartOffset(),John,null)

而不是使用setInnerHtml()可以工作。


I've been running into problem after problem trying to use the a third party HTML editor to do what (I hoped) was a simple operation. Because of these problems, I'm looking for recommendations for an alternative HTML parser I could use to perform the operations.

Here's my situation, I have span tags in my html (with an ID attribute to identify them) and I simply want to replace their contents based on an update in another area of my client. For example:

<html>
    <body>
        <p>Hello <span id="1">name</span> you are <span id="2">age</span></p>
    </body>
</html>

I've been trying to use the HTMLDocument class in javax.swing.text like this:

Element e;
e = doc.getElement(document.getDefaultRootElement(), Attribute.ID, "1");
document.setInnerHTML(element, "John");
e = doc.getElement(document.getDefaultRootElement(), Attribute.ID, "2");
document.setInnerHTML(element, "99");

but the element returned is a leaf element and won't allow the innerHTML to be set. Unfortunately, the document, reader & parser are all supplied by a 3rd party & so I can't really modify it.

So, what I was hoping for was that someone else has had a similar problem and could recommend an alternative library to do this?

Thanks in advance, B.

解决方案

Can you really not accomplish that with java.swing.text.HTMLDocument?

I have never tried this but reading through the API something along the line of

document.replace(e.getStartOffset(), e.getEndOffset()-e.getStartOffset(), "John", null)

instead of using setInnerHtml() could work.

这篇关于对java HTML解析器/编辑器的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆