所以在你的指南之后,我将代码更改为这个,但应用程序只是挂起......从这里下一步是什么?调用 getXML
Document xml = XMLemailF.getXML();
.
public static Document getXML(){
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// get a document builder
DocumentBuilder db = null;
try {
db = dbf.newDocumentBuilder();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//parse using builder to get DOM representation of the XML file
Document doc = null;
try {
doc = db.parse("/xxxxxx/res/xml/email.xml");
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return doc;
}
这就是所谓的
public static int numResults(Document doc){
Node results = doc.getDocumentElement();
int res = -1;
try{
res = Integer.valueOf(results.getAttributes().getNamedItem("count").getNodeValue());
}catch(Exception e ){
res = -1;
}
return res;
}
通过这个
...
Document xml = XMLemailF.getXML();
int numResults = XMLemailF.numResults(xml);
if((numResults <= 0)){
Toast.makeText(contactus_email.this, "No results found", Toast.LENGTH_LONG).show();
finish();
}
NodeList nodes = xml.getElementsByTagName("result");
for (int i = 0; i < nodes.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element)nodes.item(i);
map.put("email", XMLemailF.getValue(e, "email"));
map.put("line1", XMLemailF.getValue(e, "line1"));
mylist.add(map);
...
有任何想法吗?