我正在遍历此网页上的所有数据(下面的示例 xml),我对如何获取所需值感到困惑。
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet title="XSL_formatting" type="text/xsl" href="/i/xml/xsl_formatting_rss.xml"?>
<rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" version="2.0">
<channel>
<title>Ariana Resources News</title>
<link>http://www.iii.co.uk/investment/detail?code=cotn:AAU.L&display=news</link>
<description />
<item>
<title>Ariana Resources PLC - Environmental Impact Assessment Submitted for Kiziltepe</title>
<link>http://www.iii.co.uk/investment/detail?code=cotn:AAU.L&display=news&action=article&articleid=9084833&from=rss</link>
<description>Some Article information</description>
<pubDate>Fri, 30 Aug 2013 07:00:00 GMT</pubDate>
</item>
<item>
<title>Ariana Resources PLC - Directors' Dealings and Holding in Company</title>
<link>http://www.iii.co.uk/investment/detail?code=cotn:AAU.L&display=news&action=article&articleid=9053338&from=rss</link>
<description>Some Article information</description>
<pubDate>Wed, 31 Jul 2013 07:00:00 GMT</pubDate>
</item>
<item>
<title>Ariana Resources PLC - Directorship Changes</title>
<link>http://www.iii.co.uk/investment/detail?code=cotn:AAU.L&display=news&action=article&articleid=9046582&from=rss</link>
<description>Some Article information</description>
<pubDate>Wed, 24 Jul 2013 09:31:00 GMT</pubDate>
</item>
<item>
<title>Ariana Resources PLC - Ariana Resources plc : Capital Reorganisation</title>
<link>http://www.iii.co.uk/investment/detail?code=cotn:AAU.L&display=news&action=article&articleid=9038706&from=rss</link>
<description>Some Article information</description>
<pubDate>Wed, 24 Jul 2013 09:31:00 GMT</pubDate>
</item>
<item>
</channel>
</rss>
我看过dom4j快速入门指南,虽然我怀疑我只是不太明白。
我怎样才能以这样的方式进行迭代:
- 如果它有今天的日期,请浏览每个...
- 获取每个 specificall 的值,以及
在这一点上,我得到了以下内容,我认为在第二个循环中这是非常错误的......非常感谢任何帮助:
//Create a null Document Object
Document theXML = null;
//Get the document of the XML and assign to Document object
theXML = parseXML(url);
//Place the root element of theXML into a variable
Element root = theXML.getRootElement();
// iterate through child elements of root
for ( Iterator i = root.elementIterator(); i.hasNext(); ) {
Element element = (Element) i.next();
// do something
// iterate through child elements of root with element name "item"
for ( Iterator j = root.elementIterator( "item" ); j.hasNext(); ) {
Element foo = (Element) j.next();
String rnsHeadline = "";
String rnsLink = "";
String rnsFullText = "";
String rnsConstituentName = "";
Rns rns = new Rns(null, null, null, null);
}