How to get all declared elements in a DTD?

  • Henrik Motakef
    Henrik Motakef


    I wonder how I can get an elisp list of all elements declared in the current DTD.

    I need this for a completing-read in a PSGML-derived mode for a specific DTD. Basically, it should work like completion for sgml-insert-element in an element with content model ANY, i.e.  the user can choose any element declared anywhere in the DTD, and nothing else.

    I played a bit with stuff like sgml-dtd-eltypes, but it behaves in a way I don't really understand. For example,

        (lambda (x) (insert (format "%s\n" x)))
        (sgml-dtd-eltypes sgml-dtd-info))

    does _not_ insert all declared elements as I expected - there are a lot of elements missing, and some spourious zeros appear among the elements. (Replacing "(format "%s\n" x)" with "(format "%s\n" (sgml-eltype-name x))" will raise an error "wrong-type-argument symbolp 0" at the first zero that occurs)

    So, is there a simple way to get this list? Or, at least, is the structure of sgml-dtd-info documented somewhere (and is it expected to be consistent between different versions of PSGML)?


    • sgml-dtd-eltypes returns a "table of element types" not a list. The
      table is implemented as an Emacs Lisp oblist. This is rather internal
      and not well documented.

      Perhaps you can use then 'sgml-map-eltypes' function. It is
      unfortunately not documented and it doesn't seem to be in use
      (therefor not well tested). It will apply a function to every element
      type in a DTD, optionally collecting the result.

        (sgml-map-eltypes FN DTD &optional COLLECT ALL)

      (sgml-map-eltypes 'sgml-eltype-name sgml-dtd-info t)
      => ("foo" "bar" ...)