Closed itleets closed 1 month ago
I have looked briefly at Ksoup a few times in the past, but have not used it myself. The library looks fine from an API perspective and if it functions for your use-case then it's stable enough. I can't really say which library is better or worse just depends on your needs, but I can tell you why KtSoup
exists and is not built like KSoup
:
I created KtSoup quite some time before fleeksoft/ksoup
existed to fit my own use-case which had a focus on iOS and general native support. (only MohamedRejeb/Ksoup
existed then and it's not what I needed)
In terms of approach, I wanted this to be as fast as possible on native targets (among other requirements) and in my experience converting Java libraries to Kotlin Multiplatform: 1) this is generally not the type of code you want written in Kotlin for native targets as it ends up being orders of magnitude slower vs JVM. 2) Copying and converting Java to Kotlin can be a large effort and even when the project is 'done', there is likely a lot of work left to stabilize and support various API scenarios. 3) You have to constantly and carefully pull upstream changes into your code, which can be a large effort for complex bugs and major refactors. (Or you skip this part and the lib goes stale)
This was one case were I saw converting a Java codebase to Kotlin multiplatform as a generally bad idea and at the very least a major time sink for as long as the project is maintained.
So instead of rebuilding the wheel (again), this is a case were KMP's ability to interop with platform native libraries is it's most valuable asset. For JVM targets: Jsoup is small, efficient, and easy to use. For Native targets: Lexbor is small, very efficient, and has broad platform support. Both have a massive list of basic and advanced functionality that is already built and tested. So by far the simplest and most stable approach is to expect and actualize a common API surface that wraps these libraries. It took ~5 hours to create the first stable version of KtSoup that fit my use-case.
Obviously the main caveat is that KtSoup
depends on another library, but I don't see that as a practical issue in any situation:
1) It doesn't depend on Ktor/Networking libs in the core module, this was also a requirement for me.
2) You're already considering a library, so including a small API shim over-top of widely consumed and well maintained libraries is a much better approach in the long term vs a standalone reimplementation.
3) KtSoup is small and simple enough to embed in your project and maintain for your specific use-case if all else fails.
--
Some final thoughts:
Hi, I was checking out HTML parsing libraries for Kotlin Multiplatform, and I found both
fleeksoft/ksoup
and your library. I tried fleeksoft/ksoup, and it’s awesome a pure port of Jsoup with the same APIs. Have you tried it? How would you compare it to your library? I’m interested in knowing the positive points of your library compared tofleeksoft/ksoup
.My Experience with Ksoup:
Right now, I have only one concern about fleeksoft/ksoup, which is that its core depends on ktor. However, the library author mentioned this in an issue and explained that this is because library supports lot of charsets encoding/decoding other than UTF-8. The author mentioned that he is working on releasing a lite version that will only depend on kotlinx-io, but it will only support UTF-8 because kotlinx-io currently only supports that by default. He needs kotlinx-io for parsing streaming input, but for parsing strings, he may also remove that dependency.
The performance of library also tested that is very fast but little millis slower than
Jsoup
.About the stability the library is looks very stable, I see it have more than thousands unit tests which include all the unit tests from the Jsoup. It also support big range of css selectors including complex one. Author claim that library is stable ready for production.
I started using the Ksoup library from version 0.1.3, but at that time, it had some performance issues, which were fixed in version 0.1.4. Now, as it approaches version 0.1.6, it is performing very well.
Please don’t confuse it with
MohamedRejeb/Ksoup
—that’s not what I need. I'm talking aboutfleeksoft/ksoup