如何从java中的osm文件中标记'way'的元素中提取ref值?

时间:2017-07-23 21:10:45

标签: java openstreetmap

我将从OSM文件中提取ref值,如下所示:

4534884733
4534884725
4534884748
82608659
82608658
639108039
3451083060
.
.

我最终想要的是将ref值存储在文本文件中,如:

import { Constants } from 'expo';
Constants.manifest.version // your app version

有人能帮帮我吗?我可以使用任何java代码来执行此任务吗?

1 个答案:

答案 0 :(得分:0)

您应该使用Xpath

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("C://...//myFile.xml");

XPathFactory xPathfactory = XPathFactory.newInstance();
XPath xpath = xPathfactory.newXPath();
XPathExpression expr = xpath.compile("//nd/@ref");
NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);

模式"//nd/@ref"会占用所有nd元素并保持ref属性,您可以在旁边阅读它们,NodeList不可迭代您需要像阵列一样:

for (int i = 0; i < nl.getLength(); i++) 
    //write : nl.item(i).getTextContent(), somewhere
}