mirror of
https://github.com/GNOME/libxml2.git
synced 2025-03-31 19:10:28 +08:00
Header cleanup and work on parsing/output of element declarations, Daniel.
This commit is contained in:
parent
3b9def1571
commit
1899e85350
@ -1,3 +1,9 @@
|
||||
Mon Feb 1 12:10:13 CET 1999 Daniel Veillard <Daniel.Veillard@w3.org>
|
||||
|
||||
* tree.h: cleaned up using enums instead of defines
|
||||
* parser.c, valid.[ch]: more work on parsing/output of element
|
||||
declarations
|
||||
|
||||
Sun Jan 31 22:06:48 CET 1999 Daniel Veillard <Daniel.Veillard@w3.org>
|
||||
|
||||
* valid.[ch], tree.c, parser.c : more work toward full parsing
|
||||
|
@ -81,32 +81,38 @@ typedef unsigned char CHAR;
|
||||
/*
|
||||
* a DTD Element definition.
|
||||
*/
|
||||
#define XML_ELEMENT_CONTENT_PCDATA 1
|
||||
#define XML_ELEMENT_CONTENT_ELEMENT 2
|
||||
#define XML_ELEMENT_CONTENT_SEQ 3
|
||||
#define XML_ELEMENT_CONTENT_OR 4
|
||||
typedef enum {
|
||||
XML_ELEMENT_CONTENT_PCDATA=1,
|
||||
XML_ELEMENT_CONTENT_ELEMENT,
|
||||
XML_ELEMENT_CONTENT_SEQ,
|
||||
XML_ELEMENT_CONTENT_OR
|
||||
} xmlElementContentType;
|
||||
|
||||
#define XML_ELEMENT_CONTENT_ONCE 1
|
||||
#define XML_ELEMENT_CONTENT_OPT 2
|
||||
#define XML_ELEMENT_CONTENT_MULT 3
|
||||
#define XML_ELEMENT_CONTENT_PLUS 4
|
||||
typedef enum {
|
||||
XML_ELEMENT_CONTENT_ONCE=1,
|
||||
XML_ELEMENT_CONTENT_OPT,
|
||||
XML_ELEMENT_CONTENT_MULT,
|
||||
XML_ELEMENT_CONTENT_PLUS
|
||||
} xmlElementContentOccur;
|
||||
|
||||
typedef struct xmlElementContent {
|
||||
int type; /* PCDATA, ELEMENT, SEQ or OR */
|
||||
int ocur; /* ONCE, OPT, MULT or PLUS */
|
||||
const CHAR *name; /* Element name */
|
||||
xmlElementContentType type; /* PCDATA, ELEMENT, SEQ or OR */
|
||||
xmlElementContentOccur ocur; /* ONCE, OPT, MULT or PLUS */
|
||||
const CHAR *name; /* Element name */
|
||||
struct xmlElementContent *c1; /* first child */
|
||||
struct xmlElementContent *c2; /* second child */
|
||||
} xmlElementContent, *xmlElementContentPtr;
|
||||
|
||||
#define XML_ELEMENT_TYPE_EMPTY 1
|
||||
#define XML_ELEMENT_TYPE_ANY 2
|
||||
#define XML_ELEMENT_TYPE_MIXED 3
|
||||
#define XML_ELEMENT_TYPE_ELEMENT 4
|
||||
typedef enum {
|
||||
XML_ELEMENT_TYPE_EMPTY=1,
|
||||
XML_ELEMENT_TYPE_ANY,
|
||||
XML_ELEMENT_TYPE_MIXED,
|
||||
XML_ELEMENT_TYPE_ELEMENT
|
||||
} xmlElementTypeVal;
|
||||
|
||||
typedef struct xmlElement {
|
||||
const CHAR *name; /* Element name */
|
||||
int type; /* The type */
|
||||
const CHAR *name; /* Element name */
|
||||
xmlElementTypeVal type; /* The type */
|
||||
xmlElementContentPtr content; /* the allowed element content */
|
||||
} xmlElement, *xmlElementPtr;
|
||||
|
||||
@ -116,12 +122,14 @@ typedef struct xmlElement {
|
||||
* within the subtree (until overriden).
|
||||
*/
|
||||
|
||||
#define XML_GLOBAL_NAMESPACE 1 /* old style global namespace */
|
||||
#define XML_LOCAL_NAMESPACE 2 /* new style local scoping */
|
||||
typedef enum {
|
||||
XML_GLOBAL_NAMESPACE=1, /* old style global namespace */
|
||||
XML_LOCAL_NAMESPACE /* new style local scoping */
|
||||
} xmlNsType;
|
||||
|
||||
typedef struct xmlNs {
|
||||
struct xmlNs *next; /* next Ns link for this node */
|
||||
int type; /* global or local */
|
||||
xmlNsType type; /* global or local */
|
||||
const CHAR *href; /* URL for the namespace */
|
||||
const CHAR *prefix; /* prefix for the namespace */
|
||||
} xmlNs, *xmlNsPtr;
|
||||
|
@ -32,4 +32,5 @@ extern void xmlFreeElementContent(xmlElementContentPtr cur);
|
||||
|
||||
extern xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table);
|
||||
extern void xmlFreeElementTable(xmlElementTablePtr table);
|
||||
extern void xmlDumpElementTable(xmlElementTablePtr table);
|
||||
#endif /* __XML_VALID_H__ */
|
||||
|
28
parser.c
28
parser.c
@ -2379,7 +2379,7 @@ xmlParseAttributeListDecl(xmlParserCtxtPtr ctxt) {
|
||||
*/
|
||||
xmlElementContentPtr
|
||||
xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
xmlElementContentPtr ret = NULL, cur = NULL;
|
||||
xmlElementContentPtr ret = NULL, cur = NULL, n;
|
||||
CHAR *elem = NULL;
|
||||
|
||||
if ((CUR == '#') && (NXT(1) == 'P') &&
|
||||
@ -2404,16 +2404,18 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
return(NULL);
|
||||
} **********/
|
||||
while (CUR == '|') {
|
||||
NEXT;
|
||||
if (elem == NULL) {
|
||||
ret = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR);
|
||||
if (ret == NULL) return(NULL);
|
||||
ret->c1 = cur;
|
||||
cur = ret;
|
||||
} else {
|
||||
cur->c1 = xmlNewElementContent(elem,
|
||||
XML_ELEMENT_CONTENT_ELEMENT);
|
||||
cur->c2 = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR);
|
||||
cur = cur->c2;
|
||||
if (cur == NULL) return(NULL);
|
||||
n = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR);
|
||||
if (n == NULL) return(NULL);
|
||||
n->c1 = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT);
|
||||
cur->c2 = n;
|
||||
cur = n;
|
||||
}
|
||||
SKIP_BLANKS;
|
||||
elem = xmlParseName(ctxt);
|
||||
@ -2431,7 +2433,8 @@ xmlParseElementMixedContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
if (elem != NULL)
|
||||
cur->c2 = xmlNewElementContent(elem,
|
||||
XML_ELEMENT_CONTENT_ELEMENT);
|
||||
NEXT;
|
||||
ret->ocur = XML_ELEMENT_CONTENT_MULT;
|
||||
SKIP(2);
|
||||
} else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
ctxt->sax->error(ctxt,
|
||||
@ -2525,6 +2528,7 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
xmlFreeElementContent(ret);
|
||||
return(NULL);
|
||||
}
|
||||
NEXT;
|
||||
|
||||
op = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_SEQ);
|
||||
if (op == NULL) {
|
||||
@ -2538,6 +2542,7 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
cur->c2 = op;
|
||||
op->c1 = last;
|
||||
cur =op;
|
||||
last = NULL;
|
||||
}
|
||||
} else if (CUR == '|') {
|
||||
if (type == 0) type = CUR;
|
||||
@ -2554,6 +2559,7 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
xmlFreeElementContent(ret);
|
||||
return(NULL);
|
||||
}
|
||||
NEXT;
|
||||
|
||||
op = xmlNewElementContent(NULL, XML_ELEMENT_CONTENT_OR);
|
||||
if (op == NULL) {
|
||||
@ -2567,6 +2573,7 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
cur->c2 = op;
|
||||
op->c1 = last;
|
||||
cur =op;
|
||||
last = NULL;
|
||||
}
|
||||
} else {
|
||||
if ((ctxt->sax != NULL) && (ctxt->sax->error != NULL))
|
||||
@ -2581,7 +2588,7 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
/* Recurse on second child */
|
||||
NEXT;
|
||||
SKIP_BLANKS;
|
||||
cur = xmlParseElementChildrenContentDecl(ctxt);
|
||||
last = xmlParseElementChildrenContentDecl(ctxt);
|
||||
SKIP_BLANKS;
|
||||
} else {
|
||||
elem = xmlParseName(ctxt);
|
||||
@ -2592,7 +2599,7 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
ctxt->wellFormed = 0;
|
||||
return(NULL);
|
||||
}
|
||||
cur = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT);
|
||||
last = xmlNewElementContent(elem, XML_ELEMENT_CONTENT_ELEMENT);
|
||||
}
|
||||
if (CUR == '?') {
|
||||
ret->ocur = XML_ELEMENT_CONTENT_OPT;
|
||||
@ -2608,6 +2615,9 @@ xmlParseElementChildrenContentDecl(xmlParserCtxtPtr ctxt) {
|
||||
}
|
||||
SKIP_BLANKS;
|
||||
}
|
||||
if ((cur != NULL) && (last != NULL)) {
|
||||
cur->c2 = last;
|
||||
}
|
||||
NEXT;
|
||||
if (CUR == '?') {
|
||||
ret->ocur = XML_ELEMENT_CONTENT_OPT;
|
||||
|
48
tree.h
48
tree.h
@ -81,32 +81,38 @@ typedef unsigned char CHAR;
|
||||
/*
|
||||
* a DTD Element definition.
|
||||
*/
|
||||
#define XML_ELEMENT_CONTENT_PCDATA 1
|
||||
#define XML_ELEMENT_CONTENT_ELEMENT 2
|
||||
#define XML_ELEMENT_CONTENT_SEQ 3
|
||||
#define XML_ELEMENT_CONTENT_OR 4
|
||||
typedef enum {
|
||||
XML_ELEMENT_CONTENT_PCDATA=1,
|
||||
XML_ELEMENT_CONTENT_ELEMENT,
|
||||
XML_ELEMENT_CONTENT_SEQ,
|
||||
XML_ELEMENT_CONTENT_OR
|
||||
} xmlElementContentType;
|
||||
|
||||
#define XML_ELEMENT_CONTENT_ONCE 1
|
||||
#define XML_ELEMENT_CONTENT_OPT 2
|
||||
#define XML_ELEMENT_CONTENT_MULT 3
|
||||
#define XML_ELEMENT_CONTENT_PLUS 4
|
||||
typedef enum {
|
||||
XML_ELEMENT_CONTENT_ONCE=1,
|
||||
XML_ELEMENT_CONTENT_OPT,
|
||||
XML_ELEMENT_CONTENT_MULT,
|
||||
XML_ELEMENT_CONTENT_PLUS
|
||||
} xmlElementContentOccur;
|
||||
|
||||
typedef struct xmlElementContent {
|
||||
int type; /* PCDATA, ELEMENT, SEQ or OR */
|
||||
int ocur; /* ONCE, OPT, MULT or PLUS */
|
||||
const CHAR *name; /* Element name */
|
||||
xmlElementContentType type; /* PCDATA, ELEMENT, SEQ or OR */
|
||||
xmlElementContentOccur ocur; /* ONCE, OPT, MULT or PLUS */
|
||||
const CHAR *name; /* Element name */
|
||||
struct xmlElementContent *c1; /* first child */
|
||||
struct xmlElementContent *c2; /* second child */
|
||||
} xmlElementContent, *xmlElementContentPtr;
|
||||
|
||||
#define XML_ELEMENT_TYPE_EMPTY 1
|
||||
#define XML_ELEMENT_TYPE_ANY 2
|
||||
#define XML_ELEMENT_TYPE_MIXED 3
|
||||
#define XML_ELEMENT_TYPE_ELEMENT 4
|
||||
typedef enum {
|
||||
XML_ELEMENT_TYPE_EMPTY=1,
|
||||
XML_ELEMENT_TYPE_ANY,
|
||||
XML_ELEMENT_TYPE_MIXED,
|
||||
XML_ELEMENT_TYPE_ELEMENT
|
||||
} xmlElementTypeVal;
|
||||
|
||||
typedef struct xmlElement {
|
||||
const CHAR *name; /* Element name */
|
||||
int type; /* The type */
|
||||
const CHAR *name; /* Element name */
|
||||
xmlElementTypeVal type; /* The type */
|
||||
xmlElementContentPtr content; /* the allowed element content */
|
||||
} xmlElement, *xmlElementPtr;
|
||||
|
||||
@ -116,12 +122,14 @@ typedef struct xmlElement {
|
||||
* within the subtree (until overriden).
|
||||
*/
|
||||
|
||||
#define XML_GLOBAL_NAMESPACE 1 /* old style global namespace */
|
||||
#define XML_LOCAL_NAMESPACE 2 /* new style local scoping */
|
||||
typedef enum {
|
||||
XML_GLOBAL_NAMESPACE=1, /* old style global namespace */
|
||||
XML_LOCAL_NAMESPACE /* new style local scoping */
|
||||
} xmlNsType;
|
||||
|
||||
typedef struct xmlNs {
|
||||
struct xmlNs *next; /* next Ns link for this node */
|
||||
int type; /* global or local */
|
||||
xmlNsType type; /* global or local */
|
||||
const CHAR *href; /* URL for the namespace */
|
||||
const CHAR *prefix; /* prefix for the namespace */
|
||||
} xmlNs, *xmlNsPtr;
|
||||
|
88
valid.c
88
valid.c
@ -78,9 +78,8 @@ xmlCopyElementContent(xmlElementContentPtr content) {
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlNewElementContent:
|
||||
* @name: the subelement name or NULL
|
||||
* @type: the type of element content decl
|
||||
* xmlFreeElementContent:
|
||||
* @cur: the element content tree to free
|
||||
*
|
||||
* Free an element content structure. This is a recursive call !
|
||||
*/
|
||||
@ -89,6 +88,73 @@ xmlFreeElementContent(xmlElementContentPtr cur) {
|
||||
/* TODO !!! */
|
||||
}
|
||||
|
||||
/**
|
||||
* xmlDumpElementContent:
|
||||
* @content: An element table
|
||||
* @glob: 1 if one must print the englobing parenthesis, 0 otherwise
|
||||
*
|
||||
* This will dump the content of the element table as an XML DTD definition
|
||||
*
|
||||
* NOTE: TODO an extra parameter allowing a reentant implementation will
|
||||
* be added.
|
||||
*/
|
||||
void
|
||||
xmlDumpElementContent(xmlElementContentPtr content, int glob) {
|
||||
if (content == NULL) return;
|
||||
|
||||
if (glob) xmlBufferWriteChar("(");
|
||||
switch (content->type) {
|
||||
case XML_ELEMENT_CONTENT_PCDATA:
|
||||
xmlBufferWriteChar("#PCDATA");
|
||||
break;
|
||||
case XML_ELEMENT_CONTENT_ELEMENT:
|
||||
xmlBufferWriteCHAR(content->name);
|
||||
break;
|
||||
case XML_ELEMENT_CONTENT_SEQ:
|
||||
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
|
||||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ))
|
||||
xmlDumpElementContent(content->c1, 1);
|
||||
else
|
||||
xmlDumpElementContent(content->c1, 0);
|
||||
xmlBufferWriteChar(" , ");
|
||||
if (content->c2->type == XML_ELEMENT_CONTENT_OR)
|
||||
xmlDumpElementContent(content->c2, 1);
|
||||
else
|
||||
xmlDumpElementContent(content->c2, 0);
|
||||
break;
|
||||
case XML_ELEMENT_CONTENT_OR:
|
||||
if ((content->c1->type == XML_ELEMENT_CONTENT_OR) ||
|
||||
(content->c1->type == XML_ELEMENT_CONTENT_SEQ))
|
||||
xmlDumpElementContent(content->c1, 1);
|
||||
else
|
||||
xmlDumpElementContent(content->c1, 0);
|
||||
xmlBufferWriteChar(" | ");
|
||||
if (content->c2->type == XML_ELEMENT_CONTENT_SEQ)
|
||||
xmlDumpElementContent(content->c2, 1);
|
||||
else
|
||||
xmlDumpElementContent(content->c2, 0);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "xmlDumpElementContent: unknown type %d\n",
|
||||
content->type);
|
||||
}
|
||||
if (glob)
|
||||
xmlBufferWriteChar(")");
|
||||
switch (content->ocur) {
|
||||
case XML_ELEMENT_CONTENT_ONCE:
|
||||
break;
|
||||
case XML_ELEMENT_CONTENT_OPT:
|
||||
xmlBufferWriteChar("?");
|
||||
break;
|
||||
case XML_ELEMENT_CONTENT_MULT:
|
||||
xmlBufferWriteChar("*");
|
||||
break;
|
||||
case XML_ELEMENT_CONTENT_PLUS:
|
||||
xmlBufferWriteChar("+");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************
|
||||
* *
|
||||
* Registration of DTD declarations *
|
||||
@ -337,18 +403,26 @@ xmlDumpElementTable(xmlElementTablePtr table) {
|
||||
case XML_ELEMENT_TYPE_EMPTY:
|
||||
xmlBufferWriteChar("<!ELEMENT ");
|
||||
xmlBufferWriteCHAR(cur->name);
|
||||
xmlBufferWriteChar(" EMPTY>");
|
||||
xmlBufferWriteChar(" EMPTY>\n");
|
||||
break;
|
||||
case XML_ELEMENT_TYPE_ANY:
|
||||
xmlBufferWriteChar("<!ELEMENT ");
|
||||
xmlBufferWriteCHAR(cur->name);
|
||||
xmlBufferWriteChar(" ANY>");
|
||||
xmlBufferWriteChar(" ANY>\n");
|
||||
break;
|
||||
case XML_ELEMENT_TYPE_MIXED:
|
||||
/* TODO !!! */
|
||||
xmlBufferWriteChar("<!ELEMENT ");
|
||||
xmlBufferWriteCHAR(cur->name);
|
||||
xmlBufferWriteChar(" ");
|
||||
xmlDumpElementContent(cur->content, 1);
|
||||
xmlBufferWriteChar(">\n");
|
||||
break;
|
||||
case XML_ELEMENT_TYPE_ELEMENT:
|
||||
/* TODO !!! */
|
||||
xmlBufferWriteChar("<!ELEMENT ");
|
||||
xmlBufferWriteCHAR(cur->name);
|
||||
xmlBufferWriteChar(" ");
|
||||
xmlDumpElementContent(cur->content, 1);
|
||||
xmlBufferWriteChar(">\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr,
|
||||
|
1
valid.h
1
valid.h
@ -32,4 +32,5 @@ extern void xmlFreeElementContent(xmlElementContentPtr cur);
|
||||
|
||||
extern xmlElementTablePtr xmlCopyElementTable(xmlElementTablePtr table);
|
||||
extern void xmlFreeElementTable(xmlElementTablePtr table);
|
||||
extern void xmlDumpElementTable(xmlElementTablePtr table);
|
||||
#endif /* __XML_VALID_H__ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user