Re: [xml] Parse dtd



On Sun, May 08, 2005 at 08:37:37PM +0200, Rene de Zwart wrote:
I'm experimenting to make it possible to
1) Dtdparse (http://dtdparse.sf.net with libxml2)
2) do in vim as in emacs with psgml-mode. 
I need to parse a dtd for that and since libxml2 does that
already I use that.

I let libxml2 parse my dtd with the code below.
I'm stuck now with getting the dtd tree from libxml2.
I'm not getting anywhere with valid.c, hash.c, tree.c.
My questions are 
      1) how do I loop/walk over the dtd structure to get the
       information.
       I envision something like:
       Element        OPTIONS  ATTR     
       book           Req,...  id,lang  
             chapter    Req,...  id,lang  
                     title  Req,...  id,lang  
                     para   +,...    role,lang          

  walk the children list won't help in general. See valid.c code to
lookup informations in the element and attribute hash tables associated
to the internal and external subset of a document.

   2) Why does 
              xmlParseChunk(ctxt, Buff, sizeof(Buff),0)
      report  "memory:4: parser error : Document is empty"
        It seems illogical because I haven't said that I'm
        finished with xmlParseChunk (That would require the
        4th parameter to be !0.

      
static char Buff[] = {
"<?xml version='1.0' encoding='UTF-8'?>\n"
"<!DOCTYPE book PUBLIC '-//OASIS//DTD DocBook XML V4.3//EN' \n"
"'http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd'\n"
">"
};

  ugly, note that buff includes the 0 terminating the string so
Buff[sizeof(Buff)] == 0 and the parser find an end of file and rightly
complains.

  I strongly suggest you use a debugger while working on DTD lookup
code. A debugger would also have pointed out 2) fairly easilly I think.

Daniel

-- 
Daniel Veillard      | Red Hat Desktop team http://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]