📄 valid.c
字号:
} table->nb_attributes++; /* * Link it to the Dtd */ ret->parent = dtd; ret->doc = dtd->doc; if (dtd->last == NULL) { dtd->children = dtd->last = (xmlNodePtr) ret; } else { dtd->last->next = (xmlNodePtr) ret; ret->prev = dtd->last; dtd->last = (xmlNodePtr) ret; } return(ret);}/** * xmlFreeAttribute: * @elem: An attribute * * Deallocate the memory used by an attribute definition */voidxmlFreeAttribute(xmlAttributePtr attr) { if (attr == NULL) return; xmlUnlinkNode((xmlNodePtr) attr); if (attr->tree != NULL) xmlFreeEnumeration(attr->tree); if (attr->elem != NULL) xmlFree((xmlChar *) attr->elem); if (attr->name != NULL) xmlFree((xmlChar *) attr->name); if (attr->defaultValue != NULL) xmlFree((xmlChar *) attr->defaultValue); if (attr->prefix != NULL) xmlFree((xmlChar *) attr->prefix); memset(attr, -1, sizeof(xmlAttribute)); xmlFree(attr);}/** * xmlFreeAttributeTable: * @table: An attribute table * * Deallocate the memory used by an entities hash table. */voidxmlFreeAttributeTable(xmlAttributeTablePtr table) { int i; if (table == NULL) return; for (i = 0;i < table->nb_attributes;i++) { xmlFreeAttribute(table->table[i]); } xmlFree(table->table); xmlFree(table);}/** * xmlCopyAttributeTable: * @table: An attribute table * * Build a copy of an attribute table. * * Returns the new xmlAttributeTablePtr or NULL in case of error. */xmlAttributeTablePtrxmlCopyAttributeTable(xmlAttributeTablePtr table) { xmlAttributeTablePtr ret; xmlAttributePtr cur, attr; int i; ret = (xmlAttributeTablePtr) xmlMalloc(sizeof(xmlAttributeTable)); if (ret == NULL) { fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n"); return(NULL); } ret->table = (xmlAttributePtr *) xmlMalloc(table->max_attributes * sizeof(xmlAttributePtr)); if (ret->table == NULL) { fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n"); xmlFree(ret); return(NULL); } ret->max_attributes = table->max_attributes; ret->nb_attributes = table->nb_attributes; for (i = 0;i < ret->nb_attributes;i++) { attr = table->table[i]; cur = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute)); if (cur == NULL) { fprintf(stderr, "xmlCopyAttributeTable: out of memory !\n"); xmlFree(ret); xmlFree(ret->table); return(NULL); } memset(cur, 0, sizeof(xmlAttribute)); /* !!! cur->type = XML_ATTRIBUTE_DECL; */ ret->table[i] = cur; cur->atype = attr->atype; cur->def = attr->def; cur->tree = xmlCopyEnumeration(attr->tree); if (attr->elem != NULL) cur->elem = xmlStrdup(attr->elem); if (attr->name != NULL) cur->name = xmlStrdup(attr->name); if (attr->defaultValue != NULL) cur->defaultValue = xmlStrdup(attr->defaultValue); /* NEED to rebuild the next chain !!!!!! */ } return(ret);}/** * xmlDumpAttributeDecl: * @buf: the XML buffer output * @attr: An attribute declaration * * This will dump the content of the attribute declaration as an XML * DTD definition */voidxmlDumpAttributeDecl(xmlBufferPtr buf, xmlAttributePtr attr) { xmlBufferWriteChar(buf, "<!ATTLIST "); xmlBufferWriteCHAR(buf, attr->elem); xmlBufferWriteChar(buf, " "); xmlBufferWriteCHAR(buf, attr->name); switch (attr->atype) { case XML_ATTRIBUTE_CDATA: xmlBufferWriteChar(buf, " CDATA"); break; case XML_ATTRIBUTE_ID: xmlBufferWriteChar(buf, " ID"); break; case XML_ATTRIBUTE_IDREF: xmlBufferWriteChar(buf, " IDREF"); break; case XML_ATTRIBUTE_IDREFS: xmlBufferWriteChar(buf, " IDREFS"); break; case XML_ATTRIBUTE_ENTITY: xmlBufferWriteChar(buf, " ENTITY"); break; case XML_ATTRIBUTE_ENTITIES: xmlBufferWriteChar(buf, " ENTITIES"); break; case XML_ATTRIBUTE_NMTOKEN: xmlBufferWriteChar(buf, " NMTOKEN"); break; case XML_ATTRIBUTE_NMTOKENS: xmlBufferWriteChar(buf, " NMTOKENS"); break; case XML_ATTRIBUTE_ENUMERATION: xmlBufferWriteChar(buf, " ("); xmlDumpEnumeration(buf, attr->tree); break; case XML_ATTRIBUTE_NOTATION: xmlBufferWriteChar(buf, " NOTATION ("); xmlDumpEnumeration(buf, attr->tree); break; default: fprintf(stderr, "xmlDumpAttributeTable: internal: unknown type %d\n", attr->atype); } switch (attr->def) { case XML_ATTRIBUTE_NONE: break; case XML_ATTRIBUTE_REQUIRED: xmlBufferWriteChar(buf, " #REQUIRED"); break; case XML_ATTRIBUTE_IMPLIED: xmlBufferWriteChar(buf, " #IMPLIED"); break; case XML_ATTRIBUTE_FIXED: xmlBufferWriteChar(buf, " #FIXED"); break; default: fprintf(stderr, "xmlDumpAttributeTable: internal: unknown default %d\n", attr->def); } if (attr->defaultValue != NULL) { xmlBufferWriteChar(buf, " "); xmlBufferWriteQuotedString(buf, attr->defaultValue); } xmlBufferWriteChar(buf, ">\n");}/** * xmlDumpAttributeTable: * @buf: the XML buffer output * @table: An attribute table * * This will dump the content of the attribute table as an XML DTD definition */voidxmlDumpAttributeTable(xmlBufferPtr buf, xmlAttributeTablePtr table) { int i; xmlAttributePtr cur; if (table == NULL) return; for (i = 0;i < table->nb_attributes;i++) { cur = table->table[i]; xmlDumpAttributeDecl(buf, cur); }}/************************************************************************ * * * NOTATIONs * * * ************************************************************************//** * xmlCreateNotationTable: * * create and initialize an empty notation hash table. * * Returns the xmlNotationTablePtr just created or NULL in case * of error. */xmlNotationTablePtrxmlCreateNotationTable(void) { xmlNotationTablePtr ret; ret = (xmlNotationTablePtr) xmlMalloc(sizeof(xmlNotationTable)); if (ret == NULL) { fprintf(stderr, "xmlCreateNotationTable : xmlMalloc(%ld) failed\n", (long)sizeof(xmlNotationTable)); return(NULL); } ret->max_notations = XML_MIN_NOTATION_TABLE; ret->nb_notations = 0; ret->table = (xmlNotationPtr *) xmlMalloc(ret->max_notations * sizeof(xmlNotationPtr)); if (ret == NULL) { fprintf(stderr, "xmlCreateNotationTable : xmlMalloc(%ld) failed\n", ret->max_notations * (long)sizeof(xmlNotation)); xmlFree(ret); return(NULL); } return(ret);}/** * xmlAddNotationDecl: * @dtd: pointer to the DTD * @ctxt: the validation context * @name: the entity name * @PublicID: the public identifier or NULL * @SystemID: the system identifier or NULL * * Register a new notation declaration * * Returns NULL if not, othervise the entity */xmlNotationPtrxmlAddNotationDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const xmlChar *name, const xmlChar *PublicID, const xmlChar *SystemID) { xmlNotationPtr ret, cur; xmlNotationTablePtr table; int i; if (dtd == NULL) { fprintf(stderr, "xmlAddNotationDecl: dtd == NULL\n"); return(NULL); } if (name == NULL) { fprintf(stderr, "xmlAddNotationDecl: name == NULL\n"); return(NULL); } if ((PublicID == NULL) && (SystemID == NULL)) { fprintf(stderr, "xmlAddNotationDecl: no PUBLIC ID nor SYSTEM ID\n"); } /* * Create the Notation table if needed. */ table = dtd->notations; if (table == NULL) table = dtd->notations = xmlCreateNotationTable(); if (table == NULL) { fprintf(stderr, "xmlAddNotationDecl: Table creation failed!\n"); return(NULL); } /* * Validity Check: * Search the DTD for previous declarations of the ATTLIST */ for (i = 0;i < table->nb_notations;i++) { cur = table->table[i]; if (!xmlStrcmp(cur->name, name)) { /* * The notation is already defined in this Dtd. */ fprintf(stderr, "xmlAddNotationDecl: %s already defined\n", name); } } /* * Grow the table, if needed. */ if (table->nb_notations >= table->max_notations) { /* * need more notations. */ table->max_notations *= 2; table->table = (xmlNotationPtr *) xmlRealloc(table->table, table->max_notations * sizeof(xmlNotationPtr)); if (table->table == NULL) { fprintf(stderr, "xmlAddNotationDecl: out of memory\n"); return(NULL); } } ret = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation)); if (ret == NULL) { fprintf(stderr, "xmlAddNotationDecl: out of memory\n"); return(NULL); } memset(ret, 0, sizeof(xmlNotation)); table->table[table->nb_notations] = ret; /* * fill the structure. */ ret->name = xmlStrdup(name); if (SystemID != NULL) ret->SystemID = xmlStrdup(SystemID); if (PublicID != NULL) ret->PublicID = xmlStrdup(PublicID); table->nb_notations++; return(ret);}/** * xmlFreeNotation: * @not: A notation * * Deallocate the memory used by an notation definition */voidxmlFreeNotation(xmlNotationPtr nota) { if (nota == NULL) return; if (nota->name != NULL) xmlFree((xmlChar *) nota->name); if (nota->PublicID != NULL) xmlFree((xmlChar *) nota->PublicID); if (nota->SystemID != NULL) xmlFree((xmlChar *) nota->SystemID); memset(nota, -1, sizeof(xmlNotation)); xmlFree(nota);}/** * xmlFreeNotationTable: * @table: An notation table * * Deallocate the memory used by an entities hash table. */voidxmlFreeNotationTable(xmlNotationTablePtr table) { int i; if (table == NULL) return; for (i = 0;i < table->nb_notations;i++) { xmlFreeNotation(table->table[i]); } xmlFree(table->table); xmlFree(table);}/** * xmlCopyNotationTable: * @table: A notation table * * Build a copy of a notation table. * * Returns the new xmlNotationTablePtr or NULL in case of error. */xmlNotationTablePtrxmlCopyNotationTable(xmlNotationTablePtr table) { xmlNotationTablePtr ret; xmlNotationPtr cur, nota; int i; ret = (xmlNotationTablePtr) xmlMalloc(sizeof(xmlNotationTable)); if (ret == NULL) { fprintf(stderr, "xmlCopyNotationTable: out of memory !\n"); return(NULL); } ret->table = (xmlNotationPtr *) xmlMalloc(table->max_notations * sizeof(xmlNotationPtr)); if (ret->table == NULL) { fprintf(stderr, "xmlCopyNotationTable: out of memory !\n"); xmlFree(ret); return(NULL); } ret->max_notations = table->max_notations; ret->nb_notations = table->nb_notations; for (i = 0;i < ret->nb_notations;i++) { cur = (xmlNotationPtr) xmlMalloc(sizeof(xmlNotation)); if (cur == NULL) { fprintf(stderr, "xmlCopyNotationTable: out of memory !\n"); xmlFree(ret); xmlFree(ret->table); return(NULL); } ret->table[i] = cur; nota = table->table[i]; if (nota->name != NULL) cur->name = xmlStrdup(nota->name); else cur->name = NULL; if (nota->PublicID != NULL) cur->PublicID = xmlStrdup(nota->PublicID); else cur->PublicID = NULL; if (nota->SystemID != NULL) cur->SystemID = xmlStrdup(nota->SystemID); else cur->SystemID = NULL; } return(ret);}/** * xmlDumpNotationDecl: * @buf: the XML buffer output * @nota: A notation declaration * * This will dump the content the notation declaration as an XML DTD definition */voidxmlDumpNotationDecl(xmlBufferPtr buf, xmlNotationPtr nota) { xmlBufferWriteChar(buf, "<!NOTATION "); xmlBufferWriteCHAR(buf, nota->name); if (nota->PublicID != NULL) { xmlBufferWriteChar(buf, " PUBLIC "); xmlBufferWriteQuotedString(buf, nota->PublicID); if (nota->SystemID != NULL) { xmlBufferWriteChar(buf, " "); xmlBufferWriteCHAR(buf, nota->SystemID); } } else { xmlBufferWriteChar(buf, " SYSTEM "); xmlBufferWriteCHAR(buf, nota->SystemID); } xmlBufferWriteChar(buf, " >\n");}/** * xmlDumpNotationTable: * @buf: the XML buffer output * @table: A notation table * * This will dump the content of the notation table as an XML DTD definition */voidxmlDumpNotationTable(xmlBufferPtr buf, xmlNotationTablePtr table) { int i; xmlNotationPtr cur; if (table == NULL) return; for (i = 0;i < table->nb_notations;i++) { cur = table->table[i]; xmlDumpNotationDecl(buf, cur); }}/************************************************************************ * * * IDs * * * ************************************************************************//** * xmlCreateIDTable: * * create and initialize an empty id hash table. * * Returns the xmlIDTablePtr just created or NULL in case * of error. */xmlIDTablePtrxmlCreateIDTable(void) { xmlIDTablePtr ret; ret = (xmlIDTablePtr) xmlMalloc(sizeof(xmlIDTable)); if (ret == NULL) { fprintf(stderr, "xmlCreateIDTable : xmlMalloc(%ld) failed\n", (long)sizeof(xmlIDTable)); return(NULL); } ret->max_ids = XML_MIN_NOTATION_TABLE; ret->nb_ids = 0; ret->table = (xmlIDPtr *) xmlMalloc(ret->max_ids * sizeof(xmlIDPtr)); if (ret == NULL) { fprintf(stderr, "xmlCreateIDTable : xmlMalloc(%ld) failed\n", ret->max_ids * (long)sizeof(xmlID)); xmlFree(ret); return(NULL); } return(ret);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -