我正在使用此 API 进行 XML 解析“ http://cinema.dinamalar.com/rss.php ”以获取列表中的泰米尔语新闻,但它不起作用..请帮助我..这是我的代码..
public class MainActivity extends Activity {
TextView tv1,tv2,tv3;
String URL = "http://cinema.dinamalar.com/rss.php";
// XML node keys
String KEY_ITEM = "item"; // parent node
String KEY_TITLE = "title";
String KEY_LINK = "link";
String KEY_DESC = "description";
String KEY_DATE = "pubDate";
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.textView1);
tv2 = (TextView) findViewById(R.id.textView2);
tv3 = (TextView) findViewById(R.id.textView3);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
//p.getElementsByTagName('Category')[0].firstChild.wholeText
tv1.setText(parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_TITLE).toString());
tv2.setText(parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_AUTHOR).toString());
tv3.setText(parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_LINK).toString());
Toast.makeText(this,parser.getValue((Element) doc.getElementsByTagName(KEY_ITEM).item(0),KEY_LINK),Toast.LENGTH_SHORT).show();
}
}