Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This should complain if the input is not valid XML or valid KML #85

Open
tmcw opened this issue May 13, 2022 · 1 comment
Open

This should complain if the input is not valid XML or valid KML #85

tmcw opened this issue May 13, 2022 · 1 comment

Comments

@tmcw
Copy link
Collaborator

tmcw commented May 13, 2022

Options:

  • Look for the kml tag, if it is not found, return an error.
@tmcw tmcw self-assigned this May 13, 2022
@Raruto
Copy link

Raruto commented Jun 4, 2023

Here are a few lines useful to achieve this:

if (data.indexOf("<") != 0) {
  throw 'Invalid XML';
}

let xml  = (new DOMParser()).parseFromString(data, "text/xml");

let type = xml.documentElement.tagName.toLowerCase(); // "kml" or "gpx"

if (xml.getElementsByTagName('parsererror').length) {
  throw 'Invalid XML';
}

Source: leaflet-elevation/src/control.js#L956-L975

👋 Raruto

@tmcw tmcw removed their assignment Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants