[xml] Parse dtd
- From: Rene de Zwart <renez lightcon xs4all nl>
- To: xml gnome org
- Subject: [xml] Parse dtd
- Date: Sun, 8 May 2005 20:37:37 +0200
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
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"
">"
};
--------------------------------------------------------------
#include <libxml/parser.h>
#include <libxml/valid.h>
#include <libxml/tree.h>
int main(){
int ret;
xmlParserCtxtPtr ctxt;
xmlDtdPtr dtd; /* the resulting document tree */
ctxt = xmlCreatePushParserCtxt(NULL, NULL,
Buff, sizeof(Buff), "memory");
ret = xmlParseChunk(ctxt, Buff, sizeof(Buff), 0);
if (ctxt->hasExternalSubset){
dtd = xmlParseDTD(ctxt->extSubSystem,ctxt->extSubURI);
/*
What can I do to get the structure out of libxml2?
which tables do I have to walk in order to get the
info.
*/
xmlFreeDtd(dtd);
xmlCleanupParser();
}
xmlFreeParserCtxt(ctxt);
xmlMemoryDump();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]