[XML-SIG] DTD parser question

Alexandre Alexandre.Fayolle@logilab.fr
Sun, 2 Feb 2003 10:58:22 +0100

On Fri, Jan 31, 2003 at 07:00:14PM +0100, Andreas Jung wrote:
> I am currently building an XML editor using Zope. Users will see an
> XML document as tree and klick on a node. Based on the node they will
> see a toolbox with elements they can insert either as sibling or as child.
> I need to decide based on the DTD what elements are allowed to be inserted
> /deleted. I checked out the DTD parser of xmlproc and it looks very
> promising to work with however I have some problems with the
> ElementType interface:
> def get_start_state(self):
>    Returns the start state of the content model of the element. (No 
> guarantees is made as to the type of this value; just think of it as a 
> magic cookie instead.)
> def final_state(self,state):
>    Returns true if the given state (as returned by get_start_state or 
> next_state) is a final state, ie: one in which the element is allowed to 
> end.
> def next_state(self,state,elem_name):
>    Returns the next state of the element (again in an unspecified type) 
> when the an element with the given name is encountered in the given state. 
> Character data is represented as the element name '#PCDATA'. If the element 
> is not allowed in this state the value 0 will be returned.
> What are these states used for (assuming the DTD is build on a final state
> machine)? How can I use them for my projects?

You may want to check the sourcecode of the  xmleditor widget in logilab's 
xmltools, which uses the DTD Parser code from xmlproc to achieve similar
goals. It's available from ftp://ftp.logilab.org/pub/xmltools/

Alexandre Fayolle
LOGILAB, Paris (France).
http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org
Développement logiciel avancé - Intelligence Artificielle - Formations