我有下一个 XML 文档示例,我需要从文档中分离所有“链接”元素
<?xml version="1.0" encoding="ISO-8859-1" ?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://my.netscape.com/rdf/simple/0.9/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
<channel>
<title>Slashdot</title>
<link>http://slashdot.org/</link>
<description>News for nerds, stuff that matters</description>
</channel>
<image>
<title>Slashdot</title>
<url>http://a.fsdn.com/sd/topics/topicslashdot.gif</url>
<link>http://slashdot.org/</link>
</image>
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/xml" href="http://rss.slashdot.org/Slashdot/slashdot/to" />
</rdf:RDF>
这是我正在使用的代码
while (iterator.hasNext()) {
Object next = iterator.next();
Element element = (Element) next;
Namespace namespace = element.getNamespace();
Element link = element.getChild("link",namespace);
link.detach();
}
它适用于没有属性的“链接”元素
<link>http://slashdot.org/</link>
<link>http://slashdot.org/</link>
但是当我想获得下一个也是一个链接但具有属性和不同命名空间的孩子时,会返回空对象引用
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/xml" href="http://rss.slashdot.org/Slashdot/slashdot/to" />
请帮忙
非常感谢大卫