aishul.aman
aishul.aman

Reputation: 19

How to split XML String?

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.

Upvotes: 2

Views: 1029

Answers (1)

Jerome
Jerome

Reputation: 4572

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.

Upvotes: 3

Related Questions