0
我想讀從Android應用程序,但XML文件的XML文件從PHP產生的瞬間(因此文件名爲.php)的Android讀取XML錯誤
當我問該URL從Java我得到這個錯誤:在URI預期的文件格式:「http://someserver.com/foo/bar/Myuri.php」
try {
File file = new File(new URI("http://someserver.com/foo/bar/Myuri.php"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
System.out.println("Root element " + doc.getDocumentElement().getNodeName());
NodeList nodeLst = doc.getElementsByTagName("employee");
//System.out.println("Information of all employees");
for (int s = 0; s < nodeLst.getLength(); s++) {
Node fstNode = nodeLst.item(s);
if (fstNode.getNodeType() == Node.ELEMENT_NODE) {
Element fstElmnt = (Element) fstNode;
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("name");
Element fstNmElmnt = (Element) fstNmElmntLst.item(0);
NodeList fstNm = fstNmElmnt.getChildNodes();
System.out.println("Name : " + ((Node) fstNm.item(0)).getNodeValue());
NodeList lstNmElmntLst = fstElmnt.getElementsByTagName("lastname");
Element lstNmElmnt = (Element) lstNmElmntLst.item(0);
NodeList lstNm = lstNmElmnt.getChildNodes();
System.out.println("Last Name : " + ((Node) lstNm.item(0)).getNodeValue());
}
}
} catch (Exception e) {
alertDialog.setMessage(e.getMessage());
alertDialog.show();
}
你也發送PHP文件中的標題? header(「Content-type:text/xml; charset = utf-8」); – vodich
@Jon Skeet,是的,這就是我以任何方式通過它,我只是不介意提及它! –
@vodich當然,我有正確的標題,雖然我在我的Windows Phone應用程序使用相同的PHP,它工作正常 –