Giter Club home page Giter Club logo

Comments (4)

tmcw avatar tmcw commented on June 2, 2024 1

Okay, I've encountered this again in the wild, and have a plan. Basically the options are:

  • Remove namespaces from the XML as a string, using a regex, so that DOMParser can handle it. This is iffy, because regexes + XML, plus the performance effects.
  • Swap out the XML datastructure and parser for something that is more tolerant. This comes with the bonus that toGeoJSON will work in a webworker.

Hence: renaming. Going to rewrite togeojson to use htmlparser2 (which can parse XML).

from togeojson.

tmcw avatar tmcw commented on June 2, 2024

Can you post the file itself so I can help debug this?

from togeojson.

davetapley avatar davetapley commented on June 2, 2024

@tmcw sure! It was a monster, so I've removed all but one <Placemark> so I could fit in a gist, but you can still see the issue:

huc6-no-xsi.kml

huc6-with-xsi.kml


Here's a Codepen where you can see 0 vs 1 feature in browser: https://codepen.io/davetapley/pen/JjJRdBv?editors=0011

But with CLI both return the feature:

$ curl -s https://gist.githubusercontent.com/davetapley/c426f7ad68027bc292f5a03837ab50e4/raw/f5974f2e47c3af8c39b02116a160759624b0c0cd/huc6-no-xsi.kml | npx -q @tmcw/togeojson-cli | jq -e '.features | length'
1


$ curl -s https://gist.githubusercontent.com/davetapley/fa6f8e2e96b03f2911c27f20f4123107/raw/7f0b4295e367be50309be47e70f1fda3845b91bd/huc6-with-xsi.kml | npx -q @tmcw/togeojson-cli | jq -e '.features | length'
1

from togeojson.

tmcw avatar tmcw commented on June 2, 2024

Okay, I implemented this in #56 but I think that's the wrong solution. htmlparser2 is surprisingly a larger dependency than @xmldom/xmldom, and requires a lot more shifted-around code.

I think the best path here is actually just to recommend using @xmldom/xmldom as a parser, even on the web.

from togeojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.