【发布时间】:2011-10-27 00:23:46
【问题描述】:
我正在使用 import org.jdom.* 编写一个 java 应用程序;
我的 XML 是有效的,但有时它包含 HTML 标记。例如,像这样:
<program-title>Anatomy & Physiology</program-title>
<overview>
<content>
For more info click <a href="page.html">here</a>
<p>Learn more about the human body. Choose from a variety of Physiology (A&P) designed for complementary therapies.&#160; Online studies options are available.</p>
</content>
</overview>
<key-information>
<category>Health & Human Services</category>
所以我的问题在于overview.content节点内的
标签。
我希望这段代码可以工作:
Element overview = sds.getChild("overview");
Element content = overview.getChild("content");
System.out.println(content.getText());
但它返回空白。
如何从 overview.content 节点返回所有文本(嵌套标签和所有)?
谢谢
【问题讨论】:
-
嗨,当文本与其他节点混合时,如何递归地展平内容节点。例如,超链接位于句子的中间。我添加了赏金以寻求帮助。
-
需要获取内容标签内的所有HTML,包括链接和有序列表。谢谢
标签: java xml xml-parsing jdom