【发布时间】:2017-05-01 01:05:47
【问题描述】:
我有一个带有 XML 标签的字符串。
<PERSON>Obama</PERSON> is the current <POSITION>President</POSITION> of <LOCATION>United States of America<LOCATION>
我想把这些标签转换成表格
<p><span style="background-color: #99cc00;"><a style="background-color: #99cc00;" title="PERSON" href="http://usa.com">OBAMA</a></span> is the current <span style="background-color: #99cc00;"><a style="background-color: #99cc00;" title="POSITION" href="http://usa.com">President</a></span> of <span style="background-color: #99cc00;"><a style="background-color: #99cc00;" title="LOCATION" href="http://usa.com">United States of America</a></span></p>
这里的问题是用HTML标签替换XML标签(HTML中的大部分东西都是静态的,背景颜色,href等)
我是否必须使用 XML 解析器才能真正实现这一点?一个简单的正则表达式可以完成这项工作吗(我正在使用java)。任何指向此的指针将不胜感激。
【问题讨论】: