Re: [xml] Re-use code or roll my own?



On Thu, Sep 25, 2003 at 10:34:44AM +0200, Enno Rehling wrote:
I read through the relaxng implementation in libxml2 yesterday, and it has a 
couple of things I'd like to use, but hides them away. And I'm not sure if 
all I need is readily available either. If I could get some pointers here, 
that might speed up my work immensely.

The purpose of the relaxng code is to validate a document, but that's not 
really what I want to do. I want to be able to read the schema into a format 
where I can use it to decide whether it's possible to dynamically add a 
certain node into the document at some place - I don't want to validate thee 
whole thing, I want a list of potential sub-nodes that I can add to a given 
node. So, given a node in the document, I'd like to get the list of 
potential nodes I could add.

Additionally, I'd like the same thing for a node and it's attributes: A list 
of all the attributes a node could have, and their data types.

Daniel, maybe you could estimate that since you're the author of this code: 
Do you think I'll be faster trying to understand your code and turn it into 
what I want, or writing my own code?

  Hard to tell ... In general it's not simple:

   <choice>
      <element name="foo">
        <attribute name="bar1">
          <data type="anyURI"/>
        </attribute>
        <data type="integer"/>
      </element>
      <element name="foo">
        <attribute name="bar1">
          <data type="NCName"/>
        </attribute>
        <data type="NCName"/>
      </element>
   </choice>

As you can see, depending on the text content of the element,
the type (or name) of the attribute may vary.
Relax-NG is so flexible that doing the kind of work you suggest in
the general case is not trivial at all. You can't do it statically
in general, you would have to validate to then be able to make suggestions
But if you want to relax your constraints checkings, it might be
relatively easy to do this kind of lookups from libxml2 Relax-NG internals
but that will require new APIs, and some of it might not be trivial.
Now juging how long it would take, sorry I have no idea. But if you
think you don't have time to read and understand the existing code,
then I don't think you have time either to build a correct
implementation, so your question makes no sense to me. You're lucky
there is free code source available !

Daniel


-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
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]