📄 testhtml.c
字号:
/* * testHTML.c : a small tester program for HTML input. * * See Copyright for the status of this software. * * Daniel.Veillard@w3.org */#ifdef WIN32#include "win32config.h"#else#include "config.h"#endif#include "xmlversion.h"#ifdef LIBXML_HTML_ENABLED#include <stdio.h>#include <string.h>#include <stdarg.h>#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif#ifdef HAVE_SYS_STAT_H#include <sys/stat.h>#endif#ifdef HAVE_FCNTL_H#include <fcntl.h>#endif#ifdef HAVE_UNISTD_H#include <unistd.h>#endif#ifdef HAVE_STDLIB_H#include <stdlib.h>#endif#include <libxml/xmlmemory.h>#include <libxml/HTMLparser.h>#include <libxml/HTMLtree.h>#include <libxml/debugXML.h>#ifdef LIBXML_DEBUG_ENABLEDstatic int debug = 0;#endifstatic int copy = 0;static int sax = 0;static int repeat = 0;static int noout = 0;static int push = 0;xmlSAXHandler emptySAXHandlerStruct = { NULL, /* internalSubset */ NULL, /* isStandalone */ NULL, /* hasInternalSubset */ NULL, /* hasExternalSubset */ NULL, /* resolveEntity */ NULL, /* getEntity */ NULL, /* entityDecl */ NULL, /* notationDecl */ NULL, /* attributeDecl */ NULL, /* elementDecl */ NULL, /* unparsedEntityDecl */ NULL, /* setDocumentLocator */ NULL, /* startDocument */ NULL, /* endDocument */ NULL, /* startElement */ NULL, /* endElement */ NULL, /* reference */ NULL, /* characters */ NULL, /* ignorableWhitespace */ NULL, /* processingInstruction */ NULL, /* comment */ NULL, /* xmlParserWarning */ NULL, /* xmlParserError */ NULL, /* xmlParserError */ NULL, /* getParameterEntity */};xmlSAXHandlerPtr emptySAXHandler = &emptySAXHandlerStruct;extern xmlSAXHandlerPtr debugSAXHandler;/************************************************************************ * * * Debug Handlers * * * ************************************************************************//** * isStandaloneDebug: * @ctxt: An XML parser context * * Is this document tagged standalone ? * * Returns 1 if true */intisStandaloneDebug(void *ctx){ fprintf(stdout, "SAX.isStandalone()\n"); return(0);}/** * hasInternalSubsetDebug: * @ctxt: An XML parser context * * Does this document has an internal subset * * Returns 1 if true */inthasInternalSubsetDebug(void *ctx){ fprintf(stdout, "SAX.hasInternalSubset()\n"); return(0);}/** * hasExternalSubsetDebug: * @ctxt: An XML parser context * * Does this document has an external subset * * Returns 1 if true */inthasExternalSubsetDebug(void *ctx){ fprintf(stdout, "SAX.hasExternalSubset()\n"); return(0);}/** * hasInternalSubsetDebug: * @ctxt: An XML parser context * * Does this document has an internal subset */voidinternalSubsetDebug(void *ctx, const xmlChar *name, const xmlChar *ExternalID, const xmlChar *SystemID){ /* xmlDtdPtr externalSubset; */ fprintf(stdout, "SAX.internalSubset(%s, %s, %s)\n", name, ExternalID, SystemID);/*********** if ((ExternalID != NULL) || (SystemID != NULL)) { externalSubset = xmlParseDTD(ExternalID, SystemID); if (externalSubset != NULL) { xmlFreeDtd(externalSubset); } } ***********/}/** * resolveEntityDebug: * @ctxt: An XML parser context * @publicId: The public ID of the entity * @systemId: The system ID of the entity * * Special entity resolver, better left to the parser, it has * more context than the application layer. * The default behaviour is to NOT resolve the entities, in that case * the ENTITY_REF nodes are built in the structure (and the parameter * values). * * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. */xmlParserInputPtrresolveEntityDebug(void *ctx, const xmlChar *publicId, const xmlChar *systemId){ /* xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx; */ fprintf(stdout, "SAX.resolveEntity("); if (publicId != NULL) fprintf(stdout, "%s", (char *)publicId); else fprintf(stdout, " "); if (systemId != NULL) fprintf(stdout, ", %s)\n", (char *)systemId); else fprintf(stdout, ", )\n");/********* if (systemId != NULL) { return(xmlNewInputFromFile(ctxt, (char *) systemId)); } *********/ return(NULL);}/** * getEntityDebug: * @ctxt: An XML parser context * @name: The entity name * * Get an entity by name * * Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour. */xmlEntityPtrgetEntityDebug(void *ctx, const xmlChar *name){ fprintf(stdout, "SAX.getEntity(%s)\n", name); return(NULL);}/** * getParameterEntityDebug: * @ctxt: An XML parser context * @name: The entity name * * Get a parameter entity by name * * Returns the xmlParserInputPtr */xmlEntityPtrgetParameterEntityDebug(void *ctx, const xmlChar *name){ fprintf(stdout, "SAX.getParameterEntity(%s)\n", name); return(NULL);}/** * entityDeclDebug: * @ctxt: An XML parser context * @name: the entity name * @type: the entity type * @publicId: The public ID of the entity * @systemId: The system ID of the entity * @content: the entity value (without processing). * * An entity definition has been parsed */voidentityDeclDebug(void *ctx, const xmlChar *name, int type, const xmlChar *publicId, const xmlChar *systemId, xmlChar *content){ fprintf(stdout, "SAX.entityDecl(%s, %d, %s, %s, %s)\n", name, type, publicId, systemId, content);}/** * attributeDeclDebug: * @ctxt: An XML parser context * @name: the attribute name * @type: the attribute type * * An attribute definition has been parsed */voidattributeDeclDebug(void *ctx, const xmlChar *elem, const xmlChar *name, int type, int def, const xmlChar *defaultValue, xmlEnumerationPtr tree){ fprintf(stdout, "SAX.attributeDecl(%s, %s, %d, %d, %s, ...)\n", elem, name, type, def, defaultValue);}/** * elementDeclDebug: * @ctxt: An XML parser context * @name: the element name * @type: the element type * @content: the element value (without processing). * * An element definition has been parsed */voidelementDeclDebug(void *ctx, const xmlChar *name, int type, xmlElementContentPtr content){ fprintf(stdout, "SAX.elementDecl(%s, %d, ...)\n", name, type);}/** * notationDeclDebug: * @ctxt: An XML parser context * @name: The name of the notation * @publicId: The public ID of the entity * @systemId: The system ID of the entity * * What to do when a notation declaration has been parsed. */voidnotationDeclDebug(void *ctx, const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId){ fprintf(stdout, "SAX.notationDecl(%s, %s, %s)\n", (char *) name, (char *) publicId, (char *) systemId);}/** * unparsedEntityDeclDebug: * @ctxt: An XML parser context * @name: The name of the entity * @publicId: The public ID of the entity * @systemId: The system ID of the entity * @notationName: the name of the notation * * What to do when an unparsed entity declaration is parsed */voidunparsedEntityDeclDebug(void *ctx, const xmlChar *name, const xmlChar *publicId, const xmlChar *systemId, const xmlChar *notationName){ fprintf(stdout, "SAX.unparsedEntityDecl(%s, %s, %s, %s)\n", (char *) name, (char *) publicId, (char *) systemId, (char *) notationName);}/** * setDocumentLocatorDebug: * @ctxt: An XML parser context * @loc: A SAX Locator * * Receive the document locator at startup, actually xmlDefaultSAXLocator * Everything is available on the context, so this is useless in our case. */voidsetDocumentLocatorDebug(void *ctx, xmlSAXLocatorPtr loc){ fprintf(stdout, "SAX.setDocumentLocator()\n");}/** * startDocumentDebug: * @ctxt: An XML parser context * * called when the document start being processed. */voidstartDocumentDebug(void *ctx){ fprintf(stdout, "SAX.startDocument()\n");}/** * endDocumentDebug: * @ctxt: An XML parser context * * called when the document end has been detected. */voidendDocumentDebug(void *ctx){ fprintf(stdout, "SAX.endDocument()\n");}/** * startElementDebug: * @ctxt: An XML parser context * @name: The element name
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -