Re: [xml] RelaxNG Data Type support



On Sun, Dec 17, 2006 at 10:54:18PM -0800, Jason McKesson wrote:
I have some questions about the LibXML2's RelaxNG validator with
regard to data type support.

1: Does it support the standard W3C XML Schema data types?

  Yes,

2: Does it support adding custom data types?

  Hum, not as shipped, but let me explain:

2a: If so, what is the mechanism by which one goes about doing that?

  There is a internal call to do this:

/**
 * xmlRelaxNGRegisterTypeLibrary:
 * @namespace:  the URI bound to the library
 * @data:  data associated to the library
 * @have:  the provide function
 * @check:  the checking function
 * @comp:  the comparison function
 *
 * Register a new type library
 *
 * Returns 0 in case of success and -1 in case of error.
 */
static int
xmlRelaxNGRegisterTypeLibrary(const xmlChar * namespace, void *data,
                              xmlRelaxNGTypeHave have,
                              xmlRelaxNGTypeCheck check,
                              xmlRelaxNGTypeCompare comp,
                              xmlRelaxNGFacetCheck facet,
                              xmlRelaxNGTypeFree freef)

and a corresponding internal freeing operation

/**
 * xmlRelaxNGFreeTypeLibrary:
 * @lib:  the type library structure
 * @namespace:  the URI bound to the library
 *
 * Free the structure associated to the type library
 */
static void
xmlRelaxNGFreeTypeLibrary(xmlRelaxNGTypeLibraryPtr lib,
                          const xmlChar * namespace ATTRIBUTE_UNUSED)

but they are static, internal, so not exported and not usable right now.

The problem is basically that the right abstractions are not exported by 
libxml2 at this point, those typesystem are global, so adding a type system
will make it available to any validation currently running in the library.
Freeing is definitely a dangerous operation. The registration could be exported
though but since there is no thread safety lock provided, it would be better
to register the type before starting to use the library.

What could be done is the following:
   - move the definition for xmlRelaxNGTypeHave, xmlRelaxNGTypeCheck, etc...
     from relaxng.c to the public header
   - turn xmlRelaxNGRegisterTypeLibrary from static to public, export it
     from relaxng.h , expand its header to document the fact that it's
     not a thread safe operation and that once the type system has been
     installed it can't be removed.

That would probably be sufficient for most uses, but I'm not sure it's 
really a good API, I am not sure new typesystems should really be provided
globally, and the fact that you can't remove them once installed is also 
annoying.
So I tend to think this area is not fully finished, and maybe opening that
API by default is a bit risky, but I can probably be convinced to just make
the changes listed before especially if someone tries them for real and
there is positive feedback :-)

  I hope this clarifies the current situation,

Daniel

-- 
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard      | virtualization library  http://libvirt.org/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine  http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]