📄 valid.c.svn-base
字号:
* Returns the new xmlElementPtr or NULL in case of error. */static xmlElementPtrxmlCopyElement(xmlElementPtr elem) { xmlElementPtr cur; cur = (xmlElementPtr) xmlMalloc(sizeof(xmlElement)); if (cur == NULL) { xmlVErrMemory(NULL, "malloc failed"); return(NULL); } memset(cur, 0, sizeof(xmlElement)); cur->type = XML_ELEMENT_DECL; cur->etype = elem->etype; if (elem->name != NULL) cur->name = xmlStrdup(elem->name); else cur->name = NULL; if (elem->prefix != NULL) cur->prefix = xmlStrdup(elem->prefix); else cur->prefix = NULL; cur->content = xmlCopyElementContent(elem->content); /* TODO : rebuild the attribute list on the copy */ cur->attributes = NULL; return(cur);}/** * xmlCopyElementTable: * @table: An element table * * Build a copy of an element table. * * Returns the new xmlElementTablePtr or NULL in case of error. */xmlElementTablePtrxmlCopyElementTable(xmlElementTablePtr table) { return((xmlElementTablePtr) xmlHashCopy(table, (xmlHashCopier) xmlCopyElement));}#endif /* LIBXML_TREE_ENABLED */#ifdef LIBXML_OUTPUT_ENABLED/** * xmlDumpElementDecl: * @buf: the XML buffer output * @elem: An element table * * This will dump the content of the element declaration as an XML * DTD definition */voidxmlDumpElementDecl(xmlBufferPtr buf, xmlElementPtr elem) { switch (elem->etype) { case XML_ELEMENT_TYPE_EMPTY: xmlBufferWriteChar(buf, "<!ELEMENT "); if (elem->prefix != NULL) { xmlBufferWriteCHAR(buf, elem->prefix); xmlBufferWriteChar(buf, ":"); } xmlBufferWriteCHAR(buf, elem->name); xmlBufferWriteChar(buf, " EMPTY>\n"); break; case XML_ELEMENT_TYPE_ANY: xmlBufferWriteChar(buf, "<!ELEMENT "); if (elem->prefix != NULL) { xmlBufferWriteCHAR(buf, elem->prefix); xmlBufferWriteChar(buf, ":"); } xmlBufferWriteCHAR(buf, elem->name); xmlBufferWriteChar(buf, " ANY>\n"); break; case XML_ELEMENT_TYPE_MIXED: xmlBufferWriteChar(buf, "<!ELEMENT "); if (elem->prefix != NULL) { xmlBufferWriteCHAR(buf, elem->prefix); xmlBufferWriteChar(buf, ":"); } xmlBufferWriteCHAR(buf, elem->name); xmlBufferWriteChar(buf, " "); xmlDumpElementContent(buf, elem->content, 1); xmlBufferWriteChar(buf, ">\n"); break; case XML_ELEMENT_TYPE_ELEMENT: xmlBufferWriteChar(buf, "<!ELEMENT "); if (elem->prefix != NULL) { xmlBufferWriteCHAR(buf, elem->prefix); xmlBufferWriteChar(buf, ":"); } xmlBufferWriteCHAR(buf, elem->name); xmlBufferWriteChar(buf, " "); xmlDumpElementContent(buf, elem->content, 1); xmlBufferWriteChar(buf, ">\n"); break; default: xmlErrValid(NULL, XML_ERR_INTERNAL_ERROR, "Internal: ELEMENT struct corrupted invalid type\n", NULL); }}/** * xmlDumpElementDeclScan: * @elem: An element table * @buf: the XML buffer output * * This routine is used by the hash scan function. It just reverses * the arguments. */static voidxmlDumpElementDeclScan(xmlElementPtr elem, xmlBufferPtr buf) { xmlDumpElementDecl(buf, elem);}/** * xmlDumpElementTable: * @buf: the XML buffer output * @table: An element table * * This will dump the content of the element table as an XML DTD definition */voidxmlDumpElementTable(xmlBufferPtr buf, xmlElementTablePtr table) { xmlHashScan(table, (xmlHashScanner) xmlDumpElementDeclScan, buf);}#endif /* LIBXML_OUTPUT_ENABLED *//** * xmlCreateEnumeration: * @name: the enumeration name or NULL * * create and initialize an enumeration attribute node. * * Returns the xmlEnumerationPtr just created or NULL in case * of error. */xmlEnumerationPtrxmlCreateEnumeration(const xmlChar *name) { xmlEnumerationPtr ret; ret = (xmlEnumerationPtr) xmlMalloc(sizeof(xmlEnumeration)); if (ret == NULL) { xmlVErrMemory(NULL, "malloc failed"); return(NULL); } memset(ret, 0, sizeof(xmlEnumeration)); if (name != NULL) ret->name = xmlStrdup(name); return(ret);}/** * xmlFreeEnumeration: * @cur: the tree to free. * * free an enumeration attribute node (recursive). */voidxmlFreeEnumeration(xmlEnumerationPtr cur) { if (cur == NULL) return; if (cur->next != NULL) xmlFreeEnumeration(cur->next); if (cur->name != NULL) xmlFree((xmlChar *) cur->name); xmlFree(cur);}#ifdef LIBXML_TREE_ENABLED/** * xmlCopyEnumeration: * @cur: the tree to copy. * * Copy an enumeration attribute node (recursive). * * Returns the xmlEnumerationPtr just created or NULL in case * of error. */xmlEnumerationPtrxmlCopyEnumeration(xmlEnumerationPtr cur) { xmlEnumerationPtr ret; if (cur == NULL) return(NULL); ret = xmlCreateEnumeration((xmlChar *) cur->name); if (cur->next != NULL) ret->next = xmlCopyEnumeration(cur->next); else ret->next = NULL; return(ret);}#endif /* LIBXML_TREE_ENABLED */#ifdef LIBXML_OUTPUT_ENABLED/** * xmlDumpEnumeration: * @buf: the XML buffer output * @enum: An enumeration * * This will dump the content of the enumeration */static voidxmlDumpEnumeration(xmlBufferPtr buf, xmlEnumerationPtr cur) { if (cur == NULL) return; xmlBufferWriteCHAR(buf, cur->name); if (cur->next == NULL) xmlBufferWriteChar(buf, ")"); else { xmlBufferWriteChar(buf, " | "); xmlDumpEnumeration(buf, cur->next); }}#endif /* LIBXML_OUTPUT_ENABLED *//** * xmlCreateAttributeTable: * * create and initialize an empty attribute hash table. * * Returns the xmlAttributeTablePtr just created or NULL in case * of error. */static xmlAttributeTablePtrxmlCreateAttributeTable(void) { return(xmlHashCreate(0));}#ifdef LIBXML_VALID_ENABLED/** * xmlScanAttributeDeclCallback: * @attr: the attribute decl * @list: the list to update * * Callback called by xmlScanAttributeDecl when a new attribute * has to be entered in the list. */static voidxmlScanAttributeDeclCallback(xmlAttributePtr attr, xmlAttributePtr *list, const xmlChar* name ATTRIBUTE_UNUSED) { attr->nexth = *list; *list = attr;}/** * xmlScanAttributeDecl: * @dtd: pointer to the DTD * @elem: the element name * * When inserting a new element scan the DtD for existing attributes * for that element and initialize the Attribute chain * * Returns the pointer to the first attribute decl in the chain, * possibly NULL. */xmlAttributePtrxmlScanAttributeDecl(xmlDtdPtr dtd, const xmlChar *elem) { xmlAttributePtr ret = NULL; xmlAttributeTablePtr table; if (dtd == NULL) { return(NULL); } if (elem == NULL) { return(NULL); } table = (xmlAttributeTablePtr) dtd->attributes; if (table == NULL) return(NULL); /* WRONG !!! */ xmlHashScan3(table, NULL, NULL, elem, (xmlHashScanner) xmlScanAttributeDeclCallback, &ret); return(ret);}/** * xmlScanIDAttributeDecl: * @ctxt: the validation context * @elem: the element name * * Verify that the element don't have too many ID attributes * declared. * * Returns the number of ID attributes found. */static intxmlScanIDAttributeDecl(xmlValidCtxtPtr ctxt, xmlElementPtr elem) { xmlAttributePtr cur; int ret = 0; if (elem == NULL) return(0); cur = elem->attributes; while (cur != NULL) { if (cur->atype == XML_ATTRIBUTE_ID) { ret ++; if (ret > 1) xmlErrValidNode(ctxt, (xmlNodePtr) elem, XML_DTD_MULTIPLE_ID, "Element %s has too many ID attributes defined : %s\n", elem->name, cur->name, NULL); } cur = cur->nexth; } return(ret);}#endif /* LIBXML_VALID_ENABLED *//** * xmlFreeAttribute: * @elem: An attribute * * Deallocate the memory used by an attribute definition */static 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); xmlFree(attr);}/** * xmlAddAttributeDecl: * @ctxt: the validation context * @dtd: pointer to the DTD * @elem: the element name * @name: the attribute name * @ns: the attribute namespace prefix * @type: the attribute type * @def: the attribute default type * @defaultValue: the attribute default value * @tree: if it's an enumeration, the associated list * * Register a new attribute declaration * Note that @tree becomes the ownership of the DTD * * Returns NULL if not new, otherwise the attribute decl */xmlAttributePtrxmlAddAttributeDecl(xmlValidCtxtPtr ctxt, xmlDtdPtr dtd, const xmlChar *elem, const xmlChar *name, const xmlChar *ns, xmlAttributeType type, xmlAttributeDefault def, const xmlChar *defaultValue, xmlEnumerationPtr tree) { xmlAttributePtr ret; xmlAttributeTablePtr table; xmlElementPtr elemDef; if (dtd == NULL) { xmlFreeEnumeration(tree); return(NULL); } if (name == NULL) { xmlFreeEnumeration(tree); return(NULL); } if (elem == NULL) { xmlFreeEnumeration(tree); return(NULL); }#ifdef LIBXML_VALID_ENABLED /* * Check the type and possibly the default value. */ switch (type) { case XML_ATTRIBUTE_CDATA: break; case XML_ATTRIBUTE_ID: break; case XML_ATTRIBUTE_IDREF: break; case XML_ATTRIBUTE_IDREFS: break; case XML_ATTRIBUTE_ENTITY: break; case XML_ATTRIBUTE_ENTITIES: break; case XML_ATTRIBUTE_NMTOKEN: break; case XML_ATTRIBUTE_NMTOKENS: break; case XML_ATTRIBUTE_ENUMERATION: break; case XML_ATTRIBUTE_NOTATION: break; default: xmlErrValid(ctxt, XML_ERR_INTERNAL_ERROR, "Internal: ATTRIBUTE struct corrupted invalid type\n", NULL); xmlFreeEnumeration(tree); return(NULL); } if ((defaultValue != NULL) && (!xmlValidateAttributeValue(type, defaultValue))) { xmlErrValidNode(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_DEFAULT, "Attribute %s of %s: invalid default value\n", elem, name, defaultValue); defaultValue = NULL; ctxt->valid = 0; }#endif /* LIBXML_VALID_ENABLED */ /* * Check first that an attribute defined in the external subset wasn't * already defined in the internal subset */ if ((dtd->doc != NULL) && (dtd->doc->extSubset == dtd) && (dtd->doc->intSubset != NULL) && (dtd->doc->intSubset->attributes != NULL)) { ret = xmlHashLookup3(dtd->doc->intSubset->attributes, name, ns, elem); if (ret != NULL) return(NULL); } /* * Create the Attribute table if needed. */ table = (xmlAttributeTablePtr) dtd->attributes; if (table == NULL) { table = xmlCreateAttributeTable(); dtd->attributes = (void *) table; } if (table == NULL) { xmlVErrMemory(ctxt, "xmlAddAttributeDecl: Table creation failed!\n"); return(NULL); } ret = (xmlAttributePtr) xmlMalloc(sizeof(xmlAttribute)); if (ret == NULL) { xmlVErrMemory(ctxt, "malloc failed"); return(NULL); } memset(ret, 0, sizeof(xmlAttribute)); ret->type = XML_ATTRIBUTE_DECL; /* * fill the structure. */ ret->atype = type; ret->name = xmlStrdup(name); ret->prefix = xmlStrdup(ns); ret->elem = xmlStrdup(elem); ret->def = def; ret->tree = tree; if (defaultValue != NULL) ret->defaultValue = xmlStrdup(defaultValue); /* * Validity Check: * Search the DTD for previous declarations of the ATTLIST */ if (xmlHashAddEntry3(table, name, ns, elem, ret) < 0) {#ifdef LIBXML_VALID_ENABLED /* * The attribute is already defined in this DTD. */ xmlErrValidWarning(ctxt, (xmlNodePtr) dtd, XML_DTD_ATTRIBUTE_REDEFINED, "Attribute %s of element %s: already defined\n", name, elem, NULL);#endif /* LIBXML_VALID_ENABLED */ xmlFreeAttribute(ret); return(NULL); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -