Android FTP inputstream into XML

Sopgregiork

New Member
Hi im trying to read a XML-file from a FTP-server and parse it.But im not able to use my string as inputsource. I can see that im able to read the file in the LogCat and I can open the XMl-file in my browser. But Im unsure how to use the string as an inputsource. CODE:\[code\]public void readXML(){ try { Log.e("FTP", "Starting ftp session"); FTPClient ftp = new FTPClient(); Log.e("FTP", "Connecting to FTP"); ftp.connect("ftp.domain.com"); Log.e("FTP", "Providing credentials to FTP"); ftp.login("user", "pswd"); if(ftp.login("user", "pswd")){ Log.e("FTP", "Was able to connect to FTP"); } ftp.enterLocalPassiveMode(); ftp.changeWorkingDirectory("/folder/XML"); Log.e("FTP", "Getting stream"); InputStream inStream = ftp.retrieveFileStream("file.xml"); InputStreamReader isr = new InputStreamReader(inStream, "UTF8"); BufferedReader reader = new BufferedReader(isr); String Input = ""; Log.e("FTP", "Reading filestream"); do{ Input = Input + reader.readLine() + "\n"; Log.e("FTP", reader.readLine()); }while(reader.readLine()!=null); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Log.e("FTP", "Parsing inputsource"); Document doc = db.parse(new InputSource(new StringReader(Input))); doc.getDocumentElement().normalize(); Log.e("FTP", "Creating nodelist"); NodeList nodeList = doc.getElementsByTagName("TAG");\[/code\]Im unsure if StringReader is the correct way to go. EDIT:Thanks to RajeshThis is my solution:\[code\]public void readXML(){ try { Log.e("FTP", "Starting ftp session"); FTPClient ftp = new FTPClient(); Log.e("FTP", "Connecting to FTP"); ftp.connect("ftp.domain.com"); Log.e("FTP", "Providing credentials to FTP"); ftp.login("user", "pswd"); if(ftp.login("user", "pswd")){ Log.e("FTP", "Was able to connect to FTP"); } ftp.enterLocalPassiveMode(); ftp.changeWorkingDirectory("/folder/XML"); Log.e("FTP", "Getting stream"); InputStream inStream = ftp.retrieveFileStream("file.xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Log.e("FTP", "Parsing inputsource"); Document doc = db.parse(new InputSource(inStream)); doc.getDocumentElement().normalize(); Log.e("FTP", "Creating nodelist"); NodeList nodeList = doc.getElementsByTagName("TAG");\[/code\]
 
Back
Top