我正在解析 .gpx 文件并收到异常:09-01 21:00:16.603: W/System.err(11762): org.xml.sax.SAXParseException: name expected (position:START_TAG @136:28 in java.io.InputStreamReader@41887c50)
这是我的 .gpx 文件
<?xml version="1.0" encoding="utf-8"?>
<gpx><wpt>
<id>23512</id>
<lat>45.351486</lat>
<lon>36.474290</lon>
<name>Картинная галерея. г. Керчь</name>
</wpt><wpt>
<id>23512</id>
<lat>45.351486</lat>
<lon>36.474290</lon>
<name>Картинная галерея. г. Керчь</name>
</wpt><wpt>
<id>23436</id>
<lat>48.943566</lat>
<lon>34.185650</lon>
<name>Ветряк</name>
</wpt><wpt>
<id>23436</id>
<lat>48.943566</lat>
<lon>34.185650</lon>
<name>Ветряк</name>
</wpt>....
这是我的代码:onCreate:
List<Location> gpxList = null;
File gpxFile = new File(Environment.getExternalStorageDirectory()
+ "/Shukach/shukach.gpx");
gpxList = decodeGPX(gpxFile);
方法:
private List<Location> decodeGPX(File file) {
List<Location> list = new ArrayList<Location>();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
.newInstance();
try {
DocumentBuilder documentBuilder = documentBuilderFactory
.newDocumentBuilder();
FileInputStream fileInputStream = new FileInputStream(file);
Document document = documentBuilder.parse(fileInputStream);
Element elementRoot = document.getDocumentElement();
NodeList nodelist_wpt = elementRoot.getElementsByTagName("wpt");
for (int i = 0; i < nodelist_wpt.getLength(); i++) {
Node node = nodelist_wpt.item(i);
NamedNodeMap attributes = node.getAttributes();
String newLatitude = attributes.getNamedItem("lat")
.getTextContent();
Double newLatitude_double = Double.parseDouble(newLatitude);
String newLongitude = attributes.getNamedItem("lon")
.getTextContent();
Double newLongitude_double = Double.parseDouble(newLongitude);
String newLocationName = newLatitude + ":" + newLongitude;
Location newLocation = new Location(newLocationName);
newLocation.setLatitude(newLatitude_double);
newLocation.setLongitude(newLongitude_double);
list.add(newLocation);
Log.d(TAG, newLocationName);
}
fileInputStream.close();
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
我无法理解这个问题,也无法在互联网上找到解决方案......请帮助。