2
我有这个XML节点。我想用java分割坐标到纬度和经度。如何拆分XML字符串?
<MAP>1234:3.12345,119.12345</MAP>
我想分割坐标或至少可以得到与这种格式(拉特,长)的坐标。谢谢大家。
我有这个XML节点。我想用java分割坐标到纬度和经度。如何拆分XML字符串?
<MAP>1234:3.12345,119.12345</MAP>
我想分割坐标或至少可以得到与这种格式(拉特,长)的坐标。谢谢大家。
你用regex试过了吗?
final Pattern regex = Pattern.compile("<MAP>((.*):(.*),(.*))</MAP>", Pattern.DOTALL);
final Matcher matcher = regex.matcher(whatyouwanttoparselatlongwiththeaboveformat);
if (matcher.find()) {
System.out.print(matcher.group(2) + " : (lat,lon) = ");
float latitude = Float.valueOf(matcher.group(3));
float longitude = Float.valueOf(matcher.group(4));
System.out.println(latitude + "," + longitude);
}
然后,您可以根据需要处理纬度和经度。
请注意,您可能想要使用XML解析器获取节点的内容,然后将正则表达式应用于该解析器。 XML,[像HTML](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags),通常不能用正则表达式解析。但它可能没问题,这取决于你的用例的细节。 – Taymon
感谢您的答复。我只是有答案。即时通讯使用此代码String st = getCharacterDataFromElement(line); String str [] = st.split(“:”,2); 字符串latlong; latlong = str [1]; out.println(latlong); –