I would like to set up some XML parser/compiler with my Gnome app (built on default Gnome Builder template, flatpak manifest, meson build system) to do basic manipulations on svgs, something similar to what Javascript’s DOMParser and DOMSerializer provide, i.e.:
So I figured there must be bindings somewhere for JavaScript. However, the sources I ran into related to libxml2 (such as this repository) typically use npm to set it up. While having worked with npm in a few projects before, I honestly have no idea how to set it up with meson and the manifest.
Is it included in the org.gnome.Platform runtime (and where can I check that)? If so, why does adding
libxml2_dep = dependency('libxml-2.0') to src/meson.build; and
import Libxml2 from "gi://Libxml2";
lead to the following error?
JS ERROR: Error: Requiring Libxml2, version none: Typelib file for namespace 'Libxml2' (any version) not found
In the meanwhile, I have considered adding a ‘header file’ library, SVG.js project, but that’s dirty.
I also noticed that Libxml2 is among the listed libraries in the Gnome developer documentation, so I tried using the library with the following imports:
import x from "gi://Xml";
import x from "gi://Xml2";
import x from "gi://LibXml";
import x from "gi://Libxml";
import x from "gi://LibXml2";
import x from "gi://Libxml2";
import x from "gi://Libxml?version=2.0";
import x from "gi://Libxml2?version=2.0";
import x from "gi://Libxml2?version=2.14";
It kept throwing errors.
JS ERROR: Error: Requiring Libxml, version 2.14: Typelib file for namespace 'Libxml', version '2.14' not found
I fortunately noticed the title is not capitalized (though it is capitalized in the bullet). I found that the following works:
import x from "gi://libxml2";
How was I supposed to know the name of the import? Like, for Libmanette, it’s just gi://Manette. Also, how can I find the available names to import?
Furthermore, I haven’t yet found how to include npm packages or other external libraries in my app, so please feel free to redirect me to some sources or reference apps to learn it. I looked at some GJS Gnome apps, but they all use downloads.gnome.org, which is not an npm package — well, honestly, I don’t know what format it is.
That looks like not very much of anything. It’s provided by gobject-introspection itself rather than by libxml2. I don’t know why. It doesn’t look like you can actually do anything with it, since there are no functions there.
You can see the history of the file here. My guess based on this commit: it’s a fake gir used to avoid build failures when building other software? I don’t know.
Aww, that’s a bummer. I guess I should just go with the SVG.js solution and potentially investigate how I can create those bindings myself. Thanks for your input!
My educated guess: The types it provides are exposed in some other libraries’ API, so they need to be available to introspection to have working introspection for those other libraries.