2012-12-06 2 views
0

즉시 PHP에서 생성되는 XML 오류 (그래서 파일이 .PHP는)안드로이드 나는 안드로이드 응용 프로그램하지만 XML 파일에서 XML 파일을 읽기 위해 노력하고

읽기 이 오류 : 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(); 
      } 

답변

1

편집 : 자, 이제 우리는 몇 가지 코드가있어, 이제 중요한 살펴 보자 라인 :

File file = new File(new URI("http://someserver.com/foo/bar/Myuri.php")); 

File 클래스는 파일 용입니다. 임의의 URI가 아닙니다. URI에 file 스키마가 있어야합니다 (예 : file://.

기본적으로 웹에서 물건을 얻으려면 File을 사용할 수 없습니다. 그것이 그곳에있는 것이 아닙니다. HTTP 라이브러리 (예 : HttpClient.

+0

또한 헤더 파일을 PHP 파일로 보내시겠습니까? header ("Content-type : text/xml; charset = utf-8"); – vodich

+0

@ 존 스키켓, 그래, 내가 어떻게 든 그것을 통과하는 방법입니다, 나는 단지 그것을 언급하는 것을 꺼리지 않았다! –

+0

@vodich 물론 올바른 헤더가 있습니다. 동일한 PHP를 사용하고 있는데 내 Windows 전화 응용 프로그램에서 사용하고 있어도 잘 작동합니다. –