📄 valid.c
字号:
xmlElementPtrxmlGetDtdElementDesc(xmlDtdPtr dtd, const xmlChar *name) { xmlElementTablePtr table; xmlElementPtr cur; int i; if (dtd == NULL) return(NULL); if (dtd->elements == NULL) return(NULL); table = dtd->elements; for (i = 0;i < table->nb_elements;i++) { cur = table->table[i]; if (!xmlStrcmp(cur->name, name)) return(cur); } return(NULL);}/** * xmlGetDtdAttrDesc: * @dtd: a pointer to the DtD to search * @elem: the element name * @name: the attribute name * * Search the Dtd for the description of this attribute on * this element. * * returns the xmlAttributePtr if found or NULL */xmlAttributePtrxmlGetDtdAttrDesc(xmlDtdPtr dtd, const xmlChar *elem, const xmlChar *name) { xmlAttributeTablePtr table; xmlAttributePtr cur; int i; if (dtd == NULL) return(NULL); if (dtd->attributes == NULL) return(NULL); table = dtd->attributes; for (i = 0;i < table->nb_attributes;i++) { cur = table->table[i]; if ((!xmlStrcmp(cur->name, name)) && (!xmlStrcmp(cur->elem, elem))) return(cur); } return(NULL);}/** * xmlGetDtdNotationDesc: * @dtd: a pointer to the DtD to search * @name: the notation name * * Search the Dtd for the description of this notation * * returns the xmlNotationPtr if found or NULL */xmlNotationPtrxmlGetDtdNotationDesc(xmlDtdPtr dtd, const xmlChar *name) { xmlNotationTablePtr table; xmlNotationPtr cur; int i; if (dtd == NULL) return(NULL); if (dtd->notations == NULL) return(NULL); table = dtd->notations; for (i = 0;i < table->nb_notations;i++) { cur = table->table[i]; if (!xmlStrcmp(cur->name, name)) return(cur); } return(NULL);}/** * xmlValidateNotationUse: * @ctxt: the validation context * @doc: the document * @notationName: the notation name to check * * Validate that the given mame match a notation declaration. * - [ VC: Notation Declared ] * * returns 1 if valid or 0 otherwise */intxmlValidateNotationUse(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *notationName) { xmlNotationPtr notaDecl; if ((doc == NULL) || (doc->intSubset == NULL)) return(-1); notaDecl = xmlGetDtdNotationDesc(doc->intSubset, notationName); if ((notaDecl == NULL) && (doc->extSubset != NULL)) notaDecl = xmlGetDtdNotationDesc(doc->extSubset, notationName); if (notaDecl == NULL) { VERROR(ctxt->userData, "NOTATION %s is not declared\n", notationName); return(0); } return(1);}/** * xmlIsMixedElement * @doc: the document * @name: the element name * * Search in the DtDs whether an element accept Mixed content (or ANY) * basically if it is supposed to accept text childs * * returns 0 if no, 1 if yes, and -1 if no element description is available */intxmlIsMixedElement(xmlDocPtr doc, const xmlChar *name) { xmlElementPtr elemDecl; if ((doc == NULL) || (doc->intSubset == NULL)) return(-1); elemDecl = xmlGetDtdElementDesc(doc->intSubset, name); if ((elemDecl == NULL) && (doc->extSubset != NULL)) elemDecl = xmlGetDtdElementDesc(doc->extSubset, name); if (elemDecl == NULL) return(-1); switch (elemDecl->etype) { case XML_ELEMENT_TYPE_ELEMENT: return(0); case XML_ELEMENT_TYPE_EMPTY: /* * return 1 for EMPTY since we want VC error to pop up * on <empty> </empty> for example */ case XML_ELEMENT_TYPE_ANY: case XML_ELEMENT_TYPE_MIXED: return(1); } return(1);}/** * xmlValidateNameValue: * @value: an Name value * * Validate that the given value match Name production * * returns 1 if valid or 0 otherwise */intxmlValidateNameValue(const xmlChar *value) { const xmlChar *cur; if (value == NULL) return(0); cur = value; if (!IS_LETTER(*cur) && (*cur != '_') && (*cur != ':')) { return(0); } while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || (*cur == '.') || (*cur == '-') || (*cur == '_') || (*cur == ':') || (IS_COMBINING(*cur)) || (IS_EXTENDER(*cur))) cur++; if (*cur != 0) return(0); return(1);}/** * xmlValidateNamesValue: * @value: an Names value * * Validate that the given value match Names production * * returns 1 if valid or 0 otherwise */intxmlValidateNamesValue(const xmlChar *value) { const xmlChar *cur; if (value == NULL) return(0); cur = value; if (!IS_LETTER(*cur) && (*cur != '_') && (*cur != ':')) { return(0); } while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || (*cur == '.') || (*cur == '-') || (*cur == '_') || (*cur == ':') || (IS_COMBINING(*cur)) || (IS_EXTENDER(*cur))) cur++; while (IS_BLANK(*cur)) { while (IS_BLANK(*cur)) cur++; if (!IS_LETTER(*cur) && (*cur != '_') && (*cur != ':')) { return(0); } while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || (*cur == '.') || (*cur == '-') || (*cur == '_') || (*cur == ':') || (IS_COMBINING(*cur)) || (IS_EXTENDER(*cur))) cur++; } if (*cur != 0) return(0); return(1);}/** * xmlValidateNmtokenValue: * @value: an Mntoken value * * Validate that the given value match Nmtoken production * * [ VC: Name Token ] * * returns 1 if valid or 0 otherwise */intxmlValidateNmtokenValue(const xmlChar *value) { const xmlChar *cur; if (value == NULL) return(0); cur = value; if (!IS_LETTER(*cur) && !IS_DIGIT(*cur) && (*cur != '.') && (*cur != '-') && (*cur != '_') && (*cur != ':') && (!IS_COMBINING(*cur)) && (!IS_EXTENDER(*cur))) return(0); while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || (*cur == '.') || (*cur == '-') || (*cur == '_') || (*cur == ':') || (IS_COMBINING(*cur)) || (IS_EXTENDER(*cur))) cur++; if (*cur != 0) return(0); return(1);}/** * xmlValidateNmtokensValue: * @value: an Mntokens value * * Validate that the given value match Nmtokens production * * [ VC: Name Token ] * * returns 1 if valid or 0 otherwise */intxmlValidateNmtokensValue(const xmlChar *value) { const xmlChar *cur; if (value == NULL) return(0); cur = value; while (IS_BLANK(*cur)) cur++; if (!IS_LETTER(*cur) && !IS_DIGIT(*cur) && (*cur != '.') && (*cur != '-') && (*cur != '_') && (*cur != ':') && (!IS_COMBINING(*cur)) && (!IS_EXTENDER(*cur))) return(0); while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || (*cur == '.') || (*cur == '-') || (*cur == '_') || (*cur == ':') || (IS_COMBINING(*cur)) || (IS_EXTENDER(*cur))) cur++; while (IS_BLANK(*cur)) { while (IS_BLANK(*cur)) cur++; if (*cur == 0) return(1); if (!IS_LETTER(*cur) && !IS_DIGIT(*cur) && (*cur != '.') && (*cur != '-') && (*cur != '_') && (*cur != ':') && (!IS_COMBINING(*cur)) && (!IS_EXTENDER(*cur))) return(0); while ((IS_LETTER(*cur)) || (IS_DIGIT(*cur)) || (*cur == '.') || (*cur == '-') || (*cur == '_') || (*cur == ':') || (IS_COMBINING(*cur)) || (IS_EXTENDER(*cur))) cur++; } if (*cur != 0) return(0); return(1);}/** * xmlValidateNotationDecl: * @ctxt: the validation context * @doc: a document instance * @nota: a notation definition * * Try to validate a single notation definition * basically it does the following checks as described by the * XML-1.0 recommendation: * - it seems that no validity constraing exist on notation declarations * But this function get called anyway ... * * returns 1 if valid or 0 otherwise */intxmlValidateNotationDecl(xmlValidCtxtPtr ctxt, xmlDocPtr doc, xmlNotationPtr nota) { int ret = 1; return(ret);}/** * xmlValidateAttributeValue: * @type: an attribute type * @value: an attribute value * * Validate that the given attribute value match the proper production * * [ VC: ID ] * Values of type ID must match the Name production.... * * [ VC: IDREF ] * Values of type IDREF must match the Name production, and values * of type IDREFS must match Names ... * * [ VC: Entity Name ] * Values of type ENTITY must match the Name production, values * of type ENTITIES must match Names ... * * [ VC: Name Token ] * Values of type NMTOKEN must match the Nmtoken production; values * of type NMTOKENS must match Nmtokens. * * returns 1 if valid or 0 otherwise */intxmlValidateAttributeValue(xmlAttributeType type, const xmlChar *value) { switch (type) { case XML_ATTRIBUTE_ENTITIES: case XML_ATTRIBUTE_IDREFS: return(xmlValidateNamesValue(value)); case XML_ATTRIBUTE_ENTITY: case XML_ATTRIBUTE_IDREF: case XML_ATTRIBUTE_ID: case XML_ATTRIBUTE_NOTATION: return(xmlValidateNameValue(value)); case XML_ATTRIBUTE_NMTOKENS: case XML_ATTRIBUTE_ENUMERATION: return(xmlValidateNmtokensValue(value)); case XML_ATTRIBUTE_NMTOKEN: return(xmlValidateNmtokenValue(value)); case XML_ATTRIBUTE_CDATA: break; } return(1);}/** * xmlValidateAttributeValue2: * @ctxt: the validation context * @doc: the document * @name: the attribute name (used for error reporting only) * @type: the attribute type * @value: the attribute value * * Validate that the given attribute value match a given type. * This typically cannot be done before having finished parsing * the subsets. * * [ VC: IDREF ] * Values of type IDREF must match one of the declared IDs * Values of type IDREFS must match a sequence of the declared IDs * each Name must match the value of an ID attribute on some element * in the XML document; i.e. IDREF values must match the value of * some ID attribute * * [ VC: Entity Name ] * Values of type ENTITY must match one declared entity * Values of type ENTITIES must match a sequence of declared entities * * [ VC: Notation Attributes ] * all notation names in the declaration must be declared. * * returns 1 if valid or 0 otherwise */intxmlValidateAttributeValue2(xmlValidCtxtPtr ctxt, xmlDocPtr doc, const xmlChar *name, xmlAttributeType type, const xmlChar *value) { int ret = 1; switch (type) { case XML_ATTRIBUTE_IDREFS: case XML_ATTRIBUTE_IDREF: case XML_ATTRIBUTE_ID: case XML_ATTRIBUTE_NMTOKENS: case XML_ATTRIBUTE_ENUMERATION: case XML_ATTRIBUTE_NMTOKEN: case XML_ATTRIBUTE_CDATA: break; case XML_ATTRIBUTE_ENTITY: { xmlEntityPtr ent; ent = xmlGetDocEntity(doc, value); if (ent == NULL) { VERROR(ctxt->userData, "ENTITY attribute %s reference an unknown entity \"%s\"\n", name, value); ret = 0; } else if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { VERROR(ctxt->userData, "ENTITY attribute %s reference an entity \"%s\" of wrong type\n", name, value); ret = 0; } break; } case XML_ATTRIBUTE_ENTITIES: { xmlChar *dup, *nam = NULL, *cur, save; xmlEntityPtr ent; dup = xmlStrdup(value); if (dup == NULL) return(0); cur = dup; while (*cur != 0) { nam = cur; while ((*cur != 0) && (!IS_BLANK(*cur))) cur++; save = *cur; *cur = 0; ent = xmlGetDocEntity(doc, nam); if (ent == NULL) { VERROR(ctxt->userData, "ENTITIES attribute %s reference an unknown entity \"%s\"\n", name, nam); ret = 0; } else if (ent->etype != XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { VERROR(ctxt->userData, "ENTITIES attribute %s reference an entity \"%s\" of wrong type\n", name, nam); ret = 0; } if (save == 0) break; *cur = save; while (IS_BLANK(*cur)) cur++; } xmlFree(dup); break; } case XML_ATTRIBUTE_NOTATION: { xmlNotationPtr nota; nota = xmlGetDtdNotationDesc(doc->intSubset, value); if ((nota == NULL) && (doc->extSubset != NULL)) nota = xmlGetDtdNotationDesc(doc->extSubset, value); if (nota == NULL) { VERROR(ctxt->userData, "NOTATION attribute %s reference an unknown notation \"%s\"\n", name, value); ret = 0; } break; } } return(ret);}/** * xmlValidNormalizeAttributeValue: * @doc: the document * @elem: the parent * @name: the attribute name * @value: the attribute value * * Does the validation related extra step of the normalization of attribute * values: * * If the declared value is not CDATA, then the XML processor must further * process the norma
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -