這是RSS饋送的項目元素沒有得到使用了一個節點的節點的Html值RSS訂閱
- <item>
<guid isPermaLink="false">40</guid>
<category>Parking</category>
<category>Paris - Charles de Gaulle</category>
<title>Quick drop-off</title>
<description><description><span style="color: #00437f;"><strong>Trains <br />
SNCF mainline trains<br />
</strong>The Paris-Charles de Gaulle SNCF station is situated between terminals 2C-2D and 2E-2F - The station is called "Aéroport Charles de Gaulle 2 - TGV".
<p>Getting to or leaving Paris-Charles de Gaulle :<br />
- Terminals ABCDEF - accessible via the travelator<br />
-From Paris - Opéra to Paris-Charles de Gaulle<br />
Stops at the airport :<br />
- Terminals 2A, 2C, 2E-2F, 2D, 2B, 3 and 1<br />
- Terminal 2G is linked to terminal 2C (entrance 4) by the free N2 shuttle <br />
(Average travel time : 15 minutes)</p>
- Terminal 2G is linked to terminal 2C (entrance 4) by the free N2 shuttle <br />
(Average travel time : 15 minutes)</p>
Fare* : 15 € (Pass Navigo not valid)
<p> </p>
<p><strong><br />
<p> </p>
6 bus lines between Tremblay en France, Goussainville, Sarcelles, Villiers le Bel, Othis, Villeparisis and Paris-Charles de Gaulle airport.<br />
Fares* : Ticket t+, between 1,14 € and 2,28 €</p>
<div class="ll" style="border-top: #dadada 1px solid; ParaRoi=0&amp;ParaProfiling=0&amp;ParaCompte=Adp_mobile" /> 
</description>
<pubDate>Tue, 01 Dec 2009 00:00:00 +0100</pubDate>
<enclosure url="http://services.aeroportsdeparis.fr/iPhoneRessources/pict_DpMinute.png" type="image/png" />
<nbArticles>8</nbArticles>
<idSite>0</idSite>
</item>
我可以使用DOM解析器除了描述數據該父下訪問其他節點的數據。
使用下面的函數
public class Rss_Data_Retriever
{
Document myDoc;
private String[][] data=null;
public Rss_Data_Retriever(String Url)
{
InputStream in;
in=getInputStream(Url);
myDoc=getDocument(in);
}
public String getSampleString()
{
String s=getNthNodeValue("category", this.myDoc,0);
FeastingOfData(this.myDoc, "item");
return s;
}
public InputStream getInputStream(String urlString)
{
int responseCode=0;
HttpURLConnection httpurlConnection = null;
try
{
URL url=new URL(urlString);
URLConnection connection;
connection=url.openConnection();
httpurlConnection=(HttpURLConnection)connection;
responseCode=httpurlConnection.getResponseCode();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(responseCode==HttpURLConnection.HTTP_OK)
{
Log.d("Message", "httpOk");
InputStream input_fn=null;
try
{
input_fn = httpurlConnection.getInputStream();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return input_fn;
}
else
Log.d("Message", "httpNotOk");
return null;
}
public Document getDocument(InputStream inputStream)
{
DocumentBuilder builder;
NodeList docTitle = null;
Document Doc=null;
try
{
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Doc= builder.parse(inputStream);
}
catch (ParserConfigurationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (FactoryConfigurationError e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return Doc;
}
public String getNthNodeValue(String Tag,Document doc,int index)
{
DocumentBuilder builder;
NodeList docTitle = null;
Document Doc=null;
docTitle=doc.getElementsByTagName(Tag);
builder=null;
Doc=null;
Element value=(Element) docTitle.item(index);
return value.getFirstChild().getNodeValue();
}
public String getNthNodeValue(String Tag,Element element,int index,boolean isValue)
{
NodeList nodeList = null;
try
{
nodeList=element.getElementsByTagName(Tag);
}
catch (FactoryConfigurationError e)
{
}
Element value=(Element) nodeList.item(index);
if(isValue)
return value.getFirstChild().getNodeValue();
else
return value.getAttribute("url");
}
public String[][] getData()
{
return data;
}
public void FeastingOfData(Document doc,String TagName)
{
DocumentBuilder builder;
NodeList nodeList = null;
nodeList=doc.getElementsByTagName(TagName);
Log.d("Message", "Length:"+nodeList.getLength());
if(data==null)
data=new String [nodeList.getLength()][5];
int i=0;
for(i=0;i<nodeList.getLength();i++)
{
Element node=(Element) nodeList.item(i);
String maincategory=getNthNodeValue("category", node, 0,true);
String category=getNthNodeValue("category", node, 1,true);
String title=getNthNodeValue("title", node, 0,true);
String description=getNthNodeValue("description", node, 0,true);
String enclosureUrl=getNthNodeValue("enclosure", node, 0,false);
data[i][0]=maincategory;
data[i][1]=category;
data[i][2]=title;
data[i][3]=description;
data[i][4]=enclosureUrl;
Log.d("DataChecked", "maincategory:"+maincategory);
Log.d("DataChecked", "category:"+category);
Log.d("DataChecked", "title"+title);
Log.d("DataChecked", "enclosureUrl:"+enclosureUrl);
Log.d("DataChecked", "Description:"+description);
}
}
}
我試圖打印描述的節點值然後我得到了「<」簡單隻在同一時間我可以打印 類別,標題等
什麼都可以問題
問候, Kariyachan
可否請您解析後您的整個代碼? – 2011-05-31 12:51:59
我更新了我的問題 – DroidBot 2011-06-01 03:31:07
夥計們請幫助我,謝謝 – DroidBot 2011-06-02 04:48:36