में केएमएल पढ़ें और पार्स करें क्या केएमएल पार्स करने के लिए कोई लाइब्रेरी उपलब्ध है?जावा
जावा
उत्तर
आप अपनी खुद की लाइब्रेरी बनायेंगे, लेकिन आप कोई कोड नहीं लिखेंगे।
मैं सुझाव देता हूं कि http://code.google.com/apis/kml/documentation/kmlreference.html पर जाएं। वहां से आप XML Schema प्राप्त कर सकते हैं। एक बार जब आपको स्कीमा मिल जाए तो आप आसानी से पार्स और केएमएल लिखने के लिए ऑब्जेक्ट ट्री उत्पन्न करने के लिए JAXB का उपयोग कर सकते हैं।
This may also be a good resource, लगता है किसी और पहले से ही यह किया गया है!
मैं थोड़ी सी प्रैक्टिस के लिए इस सड़क पर गया, इसमें थोड़ा सा हिचकिचाहट है कि कंपाइलर के माध्यम से स्कीमा चलने पर कुछ तत्व होते हैं। कुछ भी बड़ा नहीं है, लेकिन कुछ कस्टम बाइंडिंग लिखने के लिए तैयार रहें। – CurtainDog
चूंकि यह एक्सएमएल है आप किसी भी पार्सर के साथ डेटा पढ़ सकते हैं, लेकिन अभी भी वहाँ http://code.google.com/p/libkml/ यह जावा के लिए बाइंडिंग है पर एक lib उपलब्ध है, लेकिन lib सी में है ++
इस पुस्तकालय के रूप में अच्छी तरह से वादा किया दिखता है:
http://code.google.com/p/javaapiforkml/
पुस्तकालय अब तक सहायता प्रदान करता है।
यहाँ मेरी JSOUP कार्यान्वयन आशा है कि यह वास्तव में अच्छी तरह
public ArrayList<ArrayList<LatLng>> getCoordinateArrays() {
ArrayList<ArrayList<LatLng>> allTracks = new ArrayList<ArrayList<LatLng>>();
try {
StringBuilder buf = new StringBuilder();
InputStream json = MyApplication.getInstance().getAssets().open("track.kml");
BufferedReader in = new BufferedReader(new InputStreamReader(json));
String str;
String buffer;
while ((str = in.readLine()) != null) {
buf.append(str);
}
in.close();
String html = buf.toString();
Document doc = Jsoup.parse(html, "", Parser.xmlParser());
ArrayList<String> tracksString = new ArrayList<String>();
for (Element e : doc.select("coordinates")) {
tracksString.add(e.toString().replace("<coordinates>", "").replace("</coordinates>", ""));
}
for (int i = 0; i < tracksString.size(); i++) {
ArrayList<LatLng> oneTrack = new ArrayList<LatLng>();
ArrayList<String> oneTrackString = new ArrayList<String>(Arrays.asList(tracksString.get(i).split("\\s+")));
for (int k = 1; k < oneTrackString.size(); k++) {
LatLng latLng = new LatLng(Double.parseDouble(oneTrackString.get(k).split(",")[0]),
Double.parseDouble(oneTrackString.get(k).split(",")[1]));
oneTrack.add(latLng);
}
allTracks.add(oneTrack);
}}
} catch (Exception e) {
e.printStackTrace();
}
return allTracks;
}
osmbonuspack काम करता है में मदद करता है kml डेटा से निपटने के मामले में है।
अगर आप एंड्रॉयड स्टूडियो :)
dependencies {
compile 'org.jsoup:jsoup:1.8.1'
}
// find a way to read the file and store it in a string
String inputFileContents = "";
String xmlContent = inputFileContents;
Document doc = Jsoup.parse(xml, "", Parser.xmlParser());
for(Element e : doc.select("LineString").select("coordinates")) {
// the contents
System.out.println(e.text());
}
आप एक से अधिक का चयन करें() विधि कॉल कर सकते हैं का उपयोग करें। मैं करने के लिए कोड को सरल बनाया:
Element e = doc.select("LineString").select("coordinates").first();
त्रुटि: (20, 2 9) जावा: पार्स (org.jsoup.nodes.Document.OutputSettings.Syntax, java.lang.String, org.jsoup.parser.Parser) विधि org.jsoup.Jsoup के लिए कोई उपयुक्त विधि नहीं मिली .parse (java.lang.String, java.lang.String, org.jsoup.parser.Parser) नहीं लागू (तर्क बेमेल है, org.jsoup.nodes.Document.OutputSettings.Syntax java.lang में परिवर्तित नहीं किया जा सकता है। स्ट्रिंग) विधि – user3871754
मेरे आयात: आयात org.jsoup.Jsoup; आयात org.jsoup.nodes.Document; आयात org.jsoup.nodes.Element; आयात org.jsoup.parser.Parser; आयात स्थिर org.jsoup.nodes.Document.OutputSettings.Syntax.xml; – user3871754
यह अन्य विकल्पों kml फ़ाइल सामान्य फाइल है, जो संरचना xml फ़ाइल होनी है। यह अन्य उदाहरण, खोज एक विशिष्ट स्थान-चिह्न के लिए फ़ाइल में अनेक स्थान-चिह्न
private static void readKML(InputStream fileKML, String nameCoordinates) {
String column = null;
Boolean folder = Boolean.TRUE;
Boolean placemark = Boolean.FALSE;
Boolean placeCorrect = Boolean.FALSE;
BufferedReader br = new BufferedReader(new InputStreamReader(fileKML));
try {
while ((column = br.readLine()) != null) {
if (folder) {
int ifolder = column.indexOf("<Folder>");
if (ifolder != -1) {
folder = Boolean.FALSE;
placemark = Boolean.TRUE;
continue;
}
}
if (placemark) {
String tmpLine = nameCoordinates;
tmpLine = tmpLine.replaceAll("\t", "");
tmpLine = tmpLine.replaceAll(" ", "");
String tmpColumn = column;
tmpColumn = tmpColumn.replaceAll("\t", "");
tmpColumn = tmpColumn.replaceAll(" ", "");
int name = tmpColumn.indexOf(tmpLine);
if (name != -1) {
placemark = Boolean.FALSE;
placeCorrect = Boolean.TRUE;
continue;
}
}
if (placeCorrect) {
int coordin = column.indexOf("<coordinates>");
if (coordin != -1) {
String tmpCoordin = column;
tmpCoordin = tmpCoordin.replaceAll(" ", "");
tmpCoordin = tmpCoordin.replaceAll("\t", "");
tmpCoordin = tmpCoordin.replaceAll("<coordinates>", "");
tmpCoordin = tmpCoordin
.replaceAll("</coordinates>", "");
String[] coo = tmpCoordin.split(",");
System.out.println("LONG: "+coo[0]);
System.out.println("LATI: "+coo[1])
break;
}
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
return cresp;
}
यहां अर्धविराम गायब है: System.out.println ("LATI:" + coo [1]) – user3871754
- 1. जावा: जावा
- 2. जावा जावा
- 3. समाधान जब जावा जावा
- 4. जावा के बिना जावा
- 5. जावा - जावा में प्रतिबिंब
- 6. जावा, जावा ईई
- 7. जावा: क्या जावा एप्लिकेशन
- 8. जावा
- 9. जावा
- 10. जावा
- 11. जावा
- 12. जावा
- 13. जावा
- 14. जावा
- 15. जावा
- 16. जावा
- 17. जावा,
- 18. जावा
- 19. जावा
- 20. जावा
- 21. जावा
- 22. जावा
- 23. जावा
- 24. जावा
- 25. जावा
- 26. जावा
- 27. जावा
- 28. जावा
- 29. जावा
- 30. जावा
यहाँ Jsoup के साथ मेरी कार्यान्वयन है http://stackoverflow.com/questions/1140144/read-and-parse-kml- इन-जावा/21283827 # 21283827 – alexandrius