
Hi all, I’m developing an lxml-based Python 3 app that uses the xml-model processing instruction to validate XML files against the schema associated with that file. Here’s an example of an xml-model PI: <?xml-model href="http://www.docbook.org/xml/5.0/rng/docbook.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0”?> My app would then validate the file that has this PI against the DocBook 5.0 RelaxNG schema defined in the @href attribute. For more information on the xml-model PI, see http://www.w3.org/TR/xml-model/. I can get the @href attribute of the PI just fine and use the schema it points to to validate the file, but I would really like to be able to query my XML catalog for the URI in the @href attribute and that way use a local copy of the schema instead of having to download it from an external source. The “original” libxml2 python bindings have a function called catalogResolveURI which seems to do precisely what I need. Here’s an example lifted from Stack Overflow (http://stackoverflow.com/a/7229470/825783): import libxml2 libxml2.loadCatalog('catalog.xml’) print libxml2.catalogResolveURI('file:///common/logo.xml') file:///home/kst/svn/TOOLS/Docbook/common/logo.xml I would use that function, but there doesn’t seem to be a version of libxml2 bindings for Python 3, unfortunately. So my question is, does lxml offer a way to do this? I tried browsing through the API docs and some parts of the code but I couldn’t find any way to do it. If not, would it be possible to add this feature? Or is it maybe possible to use the public C API to add this feature? If so, could you give me any pointers on how to achieve that? I’m guessing the libxml2 xmlACatalogResolveURI function (http://xmlsoft.org/html/libxml-catalog.html#xmlACatalogResolveURI) would do the job, so I guess I’d just need a way to call it via lxml. Many thanks in advance! Best, Eero Helenius

Eero Helenius schrieb am 17.08.2015 um 08:24:
libxml2 (and thus lxml) should do that automatically when resolving resources. Is that not working for you? Anyway, I think that supporting explicit catalogue lookups would be nice. It would go somewhere into docloader.pxi, either as a function or as a Catalogue class, if there's more functionality in there than just lookups. Pull requests welcome. Stefan

Hi Stefan, Thanks for the reply!
Well, this is embarrassing. I thought it didn’t, but now that you mentioned that it should, I took another look and it does indeed work as you say. That’s great! I must’ve messed something up with XML catalogs earlier. Wouldn’t be the first time. Sorry about the false alarm.
My Cython chops are non-existent, unfortunately, but if it turns out I need that feature, I might see whether I can put something together. In any case, thanks again! Best, -- Eero

Eero Helenius schrieb am 17.08.2015 um 08:24:
libxml2 (and thus lxml) should do that automatically when resolving resources. Is that not working for you? Anyway, I think that supporting explicit catalogue lookups would be nice. It would go somewhere into docloader.pxi, either as a function or as a Catalogue class, if there's more functionality in there than just lookups. Pull requests welcome. Stefan

Hi Stefan, Thanks for the reply!
Well, this is embarrassing. I thought it didn’t, but now that you mentioned that it should, I took another look and it does indeed work as you say. That’s great! I must’ve messed something up with XML catalogs earlier. Wouldn’t be the first time. Sorry about the false alarm.
My Cython chops are non-existent, unfortunately, but if it turns out I need that feature, I might see whether I can put something together. In any case, thanks again! Best, -- Eero
participants (2)
-
Eero Helenius
-
Stefan Behnel