1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-23 17:33:50 +03:00

Added prev and doc pointers to Node, confomity with DOM, Daniel

This commit is contained in:
Daniel Veillard 1998-10-14 02:36:47 +00:00
parent 9e8ce7b875
commit 0bef131b72
5 changed files with 114 additions and 18 deletions

View File

@ -1,3 +1,8 @@
Tue Oct 13 21:46:57 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* tree.h, tree.c, parser.c: added prev and doc pointers to Node,
and changed NODEs contants for conformity with DOM Level 1
Wed Oct 7 23:42:46 EDT 1998 Daniel Veillard <Daniel.Veillard@w3.org>
* added hooks to keep track of servants when creating objects

View File

@ -88,15 +88,28 @@ typedef struct xmlAttr {
/*
* A node in an XML tree.
* NOTE: This is synchronized with DOM Level1 values
* See http://www.w3.org/TR/REC-DOM-Level-1/
*/
#define XML_TYPE_TEXT 1
#define XML_TYPE_COMMENT 2
#define XML_TYPE_ENTITY 3
#define XML_ELEMENT_NODE 1
#define XML_ATTRIBUTE_NODE 2
#define XML_TEXT_NODE 3
#define XML_CDATA_SECTION_NODE 4
#define XML_ENTITY_REF_NODE 5
#define XML_ENTITY_NODE 6
#define XML_PI_NODE 7
#define XML_COMMENT_NODE 8
#define XML_DOCUMENT_NODE 9
#define XML_DOCUMENT_TYPE_NODE 10
#define XML_DOCUMENT_FRAG_NODE 11
#define XML_NOTATION_NODE 12
typedef struct xmlNode {
int type; /* type number in the DTD */
struct xmlDoc *doc; /* the containing document */
struct xmlNode *parent; /* child->parent link */
struct xmlNode *next; /* next sibling link */
struct xmlNode *prev; /* previous sibling link */
struct xmlNode *childs; /* parent->childs link */
struct xmlAttr *properties; /* properties list */
const CHAR *name; /* the name of the node, or the entity */
@ -147,9 +160,14 @@ extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
extern void xmlFreePropList(xmlAttrPtr cur);
extern void xmlFreeProp(xmlAttrPtr cur);
extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
extern xmlNodePtr xmlNewText(const CHAR *content);
extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
extern xmlNodePtr xmlNewComment(CHAR *content);
extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
@ -168,6 +186,8 @@ extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);

View File

@ -1410,7 +1410,7 @@ xmlNodePtr xmlParseComment(xmlParserCtxtPtr ctxt, int create) {
NEXT;
if (create) {
val = xmlStrndup(start, q - start);
ret = xmlNewComment(val);
ret = xmlNewDocComment(ctxt->doc, val);
free(val);
}
}
@ -2268,7 +2268,7 @@ xmlNodePtr xmlParseStartTag(xmlParserCtxtPtr ctxt) {
* attributes parsing, since local namespace can be defined as
* an attribute at this level.
*/
ret = xmlNewNode(ns, name, NULL);
ret = xmlNewDocNode(ctxt->doc, ns, name, NULL);
/*
* Now parse the attributes, it ends up with the ending

71
tree.c
View File

@ -397,10 +397,12 @@ xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content) {
return(NULL);
}
cur->doc = NULL;
cur->parent = NULL;
cur->next = NULL;
cur->childs = NULL;
cur->properties = NULL;
cur->next = NULL;
cur->prev = NULL;
cur->childs = NULL;
cur->properties = NULL;
cur->type = 0;
cur->name = xmlStrdup(name);
cur->ns = ns;
@ -413,6 +415,16 @@ xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content) {
return(cur);
}
xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
const CHAR *name, CHAR *content) {
xmlNodePtr cur;
cur = xmlNewNode(ns, name, content);
if (cur != NULL) cur->doc = doc;
return(cur);
}
/*
* Creation of a new node contening text.
*/
@ -428,11 +440,13 @@ xmlNodePtr xmlNewText(const CHAR *content) {
return(NULL);
}
cur->doc = NULL;
cur->parent = NULL;
cur->next = NULL;
cur->prev = NULL;
cur->childs = NULL;
cur->properties = NULL;
cur->type = XML_TYPE_TEXT;
cur->type = XML_TEXT_NODE;
cur->name = xmlStrdup(xmlStringText);
cur->ns = NULL;
cur->nsDef = NULL;
@ -443,6 +457,14 @@ xmlNodePtr xmlNewText(const CHAR *content) {
return(cur);
}
xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content) {
xmlNodePtr cur;
cur = xmlNewText(content);
if (cur != NULL) cur->doc = doc;
return(cur);
}
/*
* Creation of a new node contening text.
*/
@ -458,11 +480,13 @@ xmlNodePtr xmlNewTextLen(const CHAR *content, int len) {
return(NULL);
}
cur->doc = NULL;
cur->parent = NULL;
cur->prev = NULL;
cur->next = NULL;
cur->childs = NULL;
cur->properties = NULL;
cur->type = XML_TYPE_TEXT;
cur->type = XML_TEXT_NODE;
cur->name = xmlStrdup(xmlStringText);
cur->ns = NULL;
cur->nsDef = NULL;
@ -473,6 +497,14 @@ xmlNodePtr xmlNewTextLen(const CHAR *content, int len) {
return(cur);
}
xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len) {
xmlNodePtr cur;
cur = xmlNewTextLen(content, len);
if (cur != NULL) cur->doc = doc;
return(cur);
}
/*
* Creation of a new node contening a comment.
*/
@ -488,11 +520,13 @@ xmlNodePtr xmlNewComment(CHAR *content) {
return(NULL);
}
cur->doc = NULL;
cur->parent = NULL;
cur->prev = NULL;
cur->next = NULL;
cur->childs = NULL;
cur->properties = NULL;
cur->type = XML_TYPE_COMMENT;
cur->type = XML_COMMENT_NODE;
cur->name = xmlStrdup(xmlStringText);
cur->ns = NULL;
cur->nsDef = NULL;
@ -503,6 +537,14 @@ xmlNodePtr xmlNewComment(CHAR *content) {
return(cur);
}
xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content) {
xmlNodePtr cur;
cur = xmlNewComment(content);
if (cur != NULL) cur->doc = doc;
return(cur);
}
/*
* Creation of a new child element, added at the end.
*/
@ -533,12 +575,14 @@ xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
* add the new element at the end of the childs list.
*/
cur->parent = parent;
cur->doc = parent->doc;
if (parent->childs == NULL) {
parent->childs = cur;
} else {
prev = parent->childs;
while (prev->next != NULL) prev = prev->next;
prev->next = cur;
cur->prev = prev;
}
return(cur);
@ -560,16 +604,23 @@ xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur) {
return(NULL);
}
if ((cur->doc != NULL) && (parent->doc != NULL) &&
(cur->doc != parent->doc)) {
fprintf(stderr, "Elements moved to a different document\n");
}
/*
* add the new element at the end of the childs list.
*/
cur->parent = parent;
cur->doc = parent->doc; /* the parent may not be linked to a doc ! */
if (parent->childs == NULL) {
parent->childs = cur;
} else {
prev = parent->childs;
while (prev->next != NULL) prev = prev->next;
prev->next = cur;
cur->prev = prev;
}
return(cur);
@ -797,7 +848,7 @@ xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name, const CHAR *value) {
int xmlNodeIsText(xmlNodePtr node) {
if (node == NULL) return(0);
if (node->type == XML_TYPE_TEXT) return(1);
if (node->type == XML_TEXT_NODE) return(1);
return(0);
}
@ -809,7 +860,7 @@ int xmlNodeIsText(xmlNodePtr node) {
void xmlTextConcat(xmlNodePtr node, const CHAR *content, int len) {
if (node == NULL) return;
if (node->type != XML_TYPE_TEXT) {
if (node->type != XML_TEXT_NODE) {
fprintf(stderr, "xmlTextConcat: node is not text\n");
return;
}
@ -1052,12 +1103,12 @@ static void xmlNodeDump(xmlDocPtr doc, xmlNodePtr cur, int level) {
fprintf(stderr, "xmlNodeDump : node == NULL\n");
return;
}
if (cur->type == XML_TYPE_TEXT) {
if (cur->type == XML_TEXT_NODE) {
if (cur->content != NULL)
xmlBufferWriteCHAR(xmlEncodeEntities(doc, cur->content));
return;
}
if (cur->type == XML_TYPE_COMMENT) {
if (cur->type == XML_COMMENT_NODE) {
if (cur->content != NULL) {
xmlBufferWriteChar("<!--");
xmlBufferWriteCHAR(cur->content);

26
tree.h
View File

@ -88,15 +88,28 @@ typedef struct xmlAttr {
/*
* A node in an XML tree.
* NOTE: This is synchronized with DOM Level1 values
* See http://www.w3.org/TR/REC-DOM-Level-1/
*/
#define XML_TYPE_TEXT 1
#define XML_TYPE_COMMENT 2
#define XML_TYPE_ENTITY 3
#define XML_ELEMENT_NODE 1
#define XML_ATTRIBUTE_NODE 2
#define XML_TEXT_NODE 3
#define XML_CDATA_SECTION_NODE 4
#define XML_ENTITY_REF_NODE 5
#define XML_ENTITY_NODE 6
#define XML_PI_NODE 7
#define XML_COMMENT_NODE 8
#define XML_DOCUMENT_NODE 9
#define XML_DOCUMENT_TYPE_NODE 10
#define XML_DOCUMENT_FRAG_NODE 11
#define XML_NOTATION_NODE 12
typedef struct xmlNode {
int type; /* type number in the DTD */
struct xmlDoc *doc; /* the containing document */
struct xmlNode *parent; /* child->parent link */
struct xmlNode *next; /* next sibling link */
struct xmlNode *prev; /* previous sibling link */
struct xmlNode *childs; /* parent->childs link */
struct xmlAttr *properties; /* properties list */
const CHAR *name; /* the name of the node, or the entity */
@ -147,9 +160,14 @@ extern xmlAttrPtr xmlSetProp(xmlNodePtr node, const CHAR *name,
extern const CHAR *xmlGetProp(xmlNodePtr node, const CHAR *name);
extern void xmlFreePropList(xmlAttrPtr cur);
extern void xmlFreeProp(xmlAttrPtr cur);
extern xmlNodePtr xmlNewDocNode(xmlDocPtr doc, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewNode(xmlNsPtr ns, const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewDocText(xmlDocPtr doc, const CHAR *content);
extern xmlNodePtr xmlNewText(const CHAR *content);
extern xmlNodePtr xmlNewDocTextLen(xmlDocPtr doc, const CHAR *content, int len);
extern xmlNodePtr xmlNewTextLen(const CHAR *content, int len);
extern xmlNodePtr xmlNewDocComment(xmlDocPtr doc, CHAR *content);
extern xmlNodePtr xmlNewComment(CHAR *content);
extern xmlNodePtr xmlAddChild(xmlNodePtr parent, xmlNodePtr cur);
extern xmlNodePtr xmlGetLastChild(xmlNodePtr node);
@ -168,6 +186,8 @@ extern xmlNsPtr xmlSearchNsByHref(xmlDocPtr doc, xmlNodePtr node,
extern void xmlSetNs(xmlNodePtr node, xmlNsPtr ns);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern xmlNodePtr xmlNewChild(xmlNodePtr parent, xmlNsPtr ns,
const CHAR *name, CHAR *content);
extern void xmlBufferWriteCHAR(const CHAR *string);
extern void xmlBufferWriteChar(const char *string);