2

I have this xml node. I want to split the coordinate to latitude and longitude using java.

<MAP>1234:3.12345,119.12345</MAP>

I want to split the coordinate or at least can get the coordinate with this format (lat,long). Thanks all.

1 Answer 1

3

Have you tried with 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);
} 

Then you can deal with latitude and longitude as you wish.

Sign up to request clarification or add additional context in comments.

2 Comments

Note that you probably want to get the contents of the node with an XML parser and then apply the regex to that. XML, like HTML, generally cannot be parsed with regex. But it might be fine, depending on the details of your use case.
thanks for the replies. i just have the answer. im using this code String st = getCharacterDataFromElement(line); String str[] = st.split(":", 2); String latlong; latlong = str[1]; out.println(latlong);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.