Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用W3C文档对象模型如何为特定文本插入标记_Java_Html_Html Parsing_W3c - Fatal编程技术网

Java 使用W3C文档对象模型如何为特定文本插入标记

Java 使用W3C文档对象模型如何为特定文本插入标记,java,html,html-parsing,w3c,Java,Html,Html Parsing,W3c,例如,我有这样的html内容 <div>go to the text from here.<br> from there <br> Go to the text</div> 预期产出: <div>go to the <span>text</span> from here.<br> from there <br> Go to the <span>text</span>

例如,我有这样的html内容

<div>go to the text from here.<br> from there <br> Go to the text</div>
预期产出:

<div>go to the <span>text</span> from here.<br> from there <br> Go to the <span>text</span></div>
从这里转到文本。
从那里转到文本
请提供帮助。

您必须使用文本节点上的方法将其拆分为三个节点,将需要包装在元素中的单词隔离开来。然后,只需将刚刚隔离(使用)的文本节点替换为新元素。无需创建新的文本节点,只需将删除的文本节点放入添加的元素中即可


Java实现参考:。

使用哪种语言?使用哪个库(如果适用)?是什么让
text
特别呢?@minitechjava。org.w3c.dom。不仅是跨度,我还插入了锚标签和许多类似的例子
<div>go to the <span>text</span> from here.<br> from there <br> Go to the <span>text</span></div>