Код: Выделить всё
public final static Document XMLfromString(String xml) {
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
} catch (ParserConfigurationException e) {
System.out.println("XML parse error: " + e.getMessage());
return null;
} catch (SAXException e) {
System.out.println("Wrong XML file structure: " + e.getMessage());
return null;
} catch (IOException e) {
System.out.println("I/O exeption: " + e.getMessage());
return null;
}
return doc;
}
Изменил код таким образом, ибо функция parse() может принимать File.
Код: Выделить всё
// получаем путь к SD
File sdPath = Environment.getExternalStorageDirectory();
// добавляем свой каталог к пути
sdPath = new File(sdPath.getAbsolutePath() + "/" + "DIR");
// формируем объект File, который содержит путь к файлу
File sdFile = new File(sdPath, "filename.xml");
doc = db.parse(sdFile);
Код: Выделить всё
Document doc = XMLfromString();
NodeList nodes = doc.getElementsByTagName("point");