これは私のRSSファイルです。そこからデータを抽出します。私はSAXパーサーで全部の作業をしましたが、うまく動作します。しかし、私はRSSファイル全体を解析し、それぞれの要素のデータを取得しました。Rss解析の問題(XML)
しかし、私の問題は、私は全体のファイル要素のデータを取得していますが、私は唯一の要素だけが欲しいです。
<rss version="2.0">
<channel>
<title>RSS Feed</title>
<link>http://www.xyz.com</link>
<description>Calendar RSS Feeds</description>
<language>en-us</language>
<ttl>60</ttl>
<item>
<title>
title 1
</title>
<description>description 1</description>
<link>
http://www.xyz.com
</link>
<guid isPermaLink="false">[email protected]://www.xyz.com</guid>
</item>
<item>
<title>
title 2
</title>
<description>description 2</description>
<link>
http://www.xyz.com
</link>
<guid isPermaLink="false">[email protected]://www.xyz.com</guid>
</item>
<item>
</channel>
</rss>
私は私は私のコードを紹介し、これを設定するには、すべての組み合わせを試してみましたが、ここで私はのstartElementと するendElementメソッドを作った: -
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
current = true;
if (localName.equals("channel"))
{
itemList = new ItemList();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
// TODO Auto-generated method stub
current = false;
if(localName.equals("title"))
{
itemList.setTitle(currentValue);
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
// TODO Auto-generated method stub
if(current)
{
currentValue = new String(ch, start, length);
current=false;
}
}
いずれ私はretriveすることができますどのように私を提案してください要素の下にある要素。
また、私はこれを試してみましたが、これは私が事前に
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
// TODO Auto-generated method stub
current = true;
if (localName.equals("channel"))
{
if (localName.equals("item"))
{
itemList = new ItemList();
}
}
}
感謝をエラー与えます。
....それが役立つウィル願って、これを試してみてくださいDocumentBuiderで完全なデータを取得する。 DocumentBuilderでStringBufferを実装する方法を提案できますか?ありがとうございます。 – user755278
k ... RSSリーダーを作成しました。私は解析に使用したファイル全体を投稿します。ちょっと確認してください... –