parser.h revision 4fe8ee94ff7f4b4dca778979a9658d0a12b4c3e4
/*
* Summary: the core parser module
* Description: Interfaces, constants and types related to the XML parser
*
* Copy: See Copyright for the status of this software.
*
* Author: Daniel Veillard
*/
#ifndef __XML_PARSER_H__
#define __XML_PARSER_H__
#include <stdarg.h>
#include <libxml/xmlversion.h>
#include <libxml/entities.h>
#include <libxml/xmlerror.h>
#include <libxml/xmlstring.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* XML_DEFAULT_VERSION:
*
* The default version of XML used: 1.0
*/
#define XML_DEFAULT_VERSION "1.0"
/**
* xmlParserInput:
*
* An xmlParserInput is an input flow for the XML processor.
* Each entity parsed is associated an xmlParserInput (except the
* few predefined ones). This is the case both for internal entities
* - in which case the flow is already completely in memory - or
* external entities - in which case we use the buf structure for
* progressive reading and I18N conversions to the internal UTF-8 format.
*/
/**
* xmlParserInputDeallocate:
* @str: the string to deallocate
*
* Callback for freeing some parser input allocations.
*/
struct _xmlParserInput {
/* Input buffer */
const char *filename; /* The file analyzed, if any */
int length; /* length if known */
int line; /* Current line */
int col; /* Current column */
/*
* NOTE: consumed is only tested for equality in the parser code,
* so even if there is an overflow this should not give troubles
* for parsing very large instances.
*/
unsigned long consumed; /* How many xmlChars already consumed */
int standalone; /* Was that entity marked standalone */
int id; /* an unique identifier for the entity */
};
/**
* xmlParserNodeInfo:
*
* The parser can be asked to collect Node informations, i.e. at what
* place in the file they were detected.
* NOTE: This is off by default and not very well tested.
*/
typedef struct _xmlParserNodeInfo xmlParserNodeInfo;
typedef xmlParserNodeInfo *xmlParserNodeInfoPtr;
struct _xmlParserNodeInfo {
/* Position & line # that text that created the node begins & ends on */
unsigned long begin_pos;
unsigned long begin_line;
unsigned long end_pos;
unsigned long end_line;
};
typedef struct _xmlParserNodeInfoSeq xmlParserNodeInfoSeq;
typedef xmlParserNodeInfoSeq *xmlParserNodeInfoSeqPtr;
struct _xmlParserNodeInfoSeq {
unsigned long maximum;
unsigned long length;
};
/**
* xmlParserInputState:
*
* The parser is now working also as a state based parser.
* The recursive one use the state info for entities processing.
*/
typedef enum {
XML_PARSER_START = 0, /* nothing has been parsed */
XML_PARSER_MISC, /* Misc* before int subset */
XML_PARSER_PI, /* Within a processing instruction */
XML_PARSER_DTD, /* within some DTD content */
XML_PARSER_PROLOG, /* Misc* after internal subset */
XML_PARSER_COMMENT, /* within a comment */
XML_PARSER_START_TAG, /* within a start tag */
XML_PARSER_CONTENT, /* within the content */
XML_PARSER_CDATA_SECTION, /* within a CDATA section */
XML_PARSER_END_TAG, /* within a closing tag */
XML_PARSER_ENTITY_DECL, /* within an entity declaration */
XML_PARSER_ENTITY_VALUE, /* within an entity value in a decl */
XML_PARSER_ATTRIBUTE_VALUE, /* within an attribute value */
XML_PARSER_SYSTEM_LITERAL, /* within a SYSTEM value */
XML_PARSER_EPILOG, /* the Misc* after the last end tag */
XML_PARSER_IGNORE, /* within an IGNORED section */
XML_PARSER_PUBLIC_LITERAL /* within a PUBLIC value */
/**
* XML_DETECT_IDS:
*
* Use it to initialize xmlLoadExtDtdDefaultValue.
*/
#define XML_DETECT_IDS 2
/**
* XML_COMPLETE_ATTRS:
*
* Bit in the loadsubset context field to tell to do complete the
* elements attributes lists with the ones defaulted from the DTDs.
* Use it to initialize xmlLoadExtDtdDefaultValue.
*/
#define XML_COMPLETE_ATTRS 4
/**
* XML_SKIP_IDS:
*
* Used to initialize xmlLoadExtDtdDefaultValue in some special cases.
*/
#define XML_SKIP_IDS 8
/**
* xmlParserMode:
*
* A parser can operate in various modes
*/
typedef enum {
XML_PARSE_UNKNOWN = 0,
XML_PARSE_DOM = 1,
XML_PARSE_SAX = 2,
XML_PARSE_PUSH_DOM = 3,
XML_PARSE_PUSH_SAX = 4,
XML_PARSE_READER = 5
/**
* xmlParserCtxt:
*
* The parser context.
* NOTE This doesn't completely define the parser state, the (current ?)
* design of the parser uses recursive function calls since this allow
* and easy mapping from the production rules of the specification
* to the actual code. The drawback is that the actual function call
* also reflect the parser state. However most of the parsing routines
* takes as the only argument the parser context pointer, so migrating
* to a state based parser for progressive parsing shouldn't be too hard.
*/
struct _xmlParserCtxt {
void *userData; /* For SAX interface only, used by DOM build */
int wellFormed; /* is the document well formed */
int replaceEntities; /* shall we replace entities ? */
int standalone; /* standalone document */
int html; /* an HTML(1)/Docbook(2) document */
/* Input stream stack */
int inputNr; /* Number of current input streams */
int inputMax; /* Max number of input streams */
/* Node analysis stack only used for DOM building */
int nodeNr; /* Depth of the parsing stack */
int nodeMax; /* Max depth of the parsing stack */
int record_info; /* Whether node info should be kept */
int errNo; /* error code */
int hasExternalSubset; /* reference and external subset */
int hasPErefs; /* the internal subset has PE refs */
int external; /* are we parsing an external entity */
int valid; /* is the document valid */
int validate; /* shall we try to validate ? */
int token; /* next char look-ahead */
char *directory; /* the data directory */
/* Node name stack */
int nameNr; /* Depth of the parsing stack */
int nameMax; /* Max depth of the parsing stack */
long nbChars; /* number of xmlChar processed */
long checkIndex; /* used by progressive parsing lookup */
int keepBlanks; /* ugly but ... */
int disableSAX; /* SAX callbacks are disabled */
int inSubset; /* Parsing is in int 1/ext 2 subset */
/* xml:space values */
int * space; /* Should the parser preserve spaces */
int spaceNr; /* Depth of the parsing stack */
int spaceMax; /* Max depth of the parsing stack */
int * spaceTab; /* array of space infos */
int depth; /* to prevent entity substitution loops */
int charset; /* encoding of the in-memory content
actually an xmlCharEncoding */
int nodelen; /* Those two fields are there to */
int nodemem; /* Speed up large node parsing */
int pedantic; /* signal pedantic warnings */
void *_private; /* For user data, libxml won't touch it */
int loadsubset; /* should the external subset be loaded */
int linenumbers; /* set line number in element content */
void *catalogs; /* document's own catalog */
int recovery; /* run in recovery mode */
int progressive; /* is this a progressive parsing */
int maxatts; /* the size of the array */
int docdict; /* use strings from dict to build tree */
/*
* pre-interned strings
*/
const xmlChar *str_xml_ns;
/*
* Everything below is used only by the new SAX mode
*/
int sax2; /* operating in the new SAX mode */
int nsNr; /* the number of inherited namespaces */
int nsMax; /* the size of the arrays */
int *attallocs; /* which attribute were allocated */
void * *pushTab; /* array of data for push */
int nsWellFormed; /* is the document XML Nanespace okay */
int options; /* Extra options */
/*
* Those fields are needed only for treaming parsing so far
*/
int dictNames; /* Use dictionary names for the tree */
int freeElemsNr; /* number of freed element nodes */
int freeAttrsNr; /* number of freed attributes nodes */
/*
* the complete error informations for the last error.
*/
unsigned long nbentities; /* number of entities references */
unsigned long sizeentities; /* size of parsed entities */
unsigned long sizeentcopy; /* volume of entity copy */
};
/**
* xmlSAXLocator:
*
* A SAX Locator.
*/
struct _xmlSAXLocator {
int (*getLineNumber)(void *ctx);
int (*getColumnNumber)(void *ctx);
};
/**
* xmlSAXHandler:
*
* A SAX handler is bunch of callbacks called by the parser when processing
* of the input generate data or structure informations.
*/
/**
* resolveEntitySAXFunc:
* @ctx: the user data (XML parser context)
* @publicId: The public ID of the entity
* @systemId: The system ID of the entity
*
* Callback:
* The entity loader, to control the loading of external entities,
* the application can either:
* - override this resolveEntity() callback in the SAX block
* - or better use the xmlSetExternalEntityLoader() function to
* set up it's own entity resolution routine
*
* Returns the xmlParserInputPtr if inlined or NULL for DOM behaviour.
*/
/**
* internalSubsetSAXFunc:
* @ctx: the user data (XML parser context)
* @name: the root element name
* @ExternalID: the external ID
* @SystemID: the SYSTEM ID (e.g. filename or URL)
*
* Callback on internal subset declaration.
*/
typedef void (*internalSubsetSAXFunc) (void *ctx,
const xmlChar *ExternalID,
/**
* externalSubsetSAXFunc:
* @ctx: the user data (XML parser context)
* @name: the root element name
* @ExternalID: the external ID
* @SystemID: the SYSTEM ID (e.g. filename or URL)
*
* Callback on external subset declaration.
*/
typedef void (*externalSubsetSAXFunc) (void *ctx,
const xmlChar *ExternalID,
/**
* getEntitySAXFunc:
* @ctx: the user data (XML parser context)
* @name: The entity name
*
* Get an entity by name.
*
* Returns the xmlEntityPtr if found.
*/
/**
* getParameterEntitySAXFunc:
* @ctx: the user data (XML parser context)
* @name: The entity name
*
* Get a parameter entity by name.
*
* Returns the xmlEntityPtr if found.
*/
/**
* entityDeclSAXFunc:
* @ctx: the user data (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.
*/
typedef void (*entityDeclSAXFunc) (void *ctx,
int type,
/**
* notationDeclSAXFunc:
* @ctx: the user data (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.
*/
typedef void (*notationDeclSAXFunc)(void *ctx,
/**
* attributeDeclSAXFunc:
* @ctx: the user data (XML parser context)
* @elem: the name of the element
* @fullname: the attribute name
* @type: the attribute type
* @def: the type of default value
* @defaultValue: the attribute default value
* @tree: the tree of enumerated value set
*
* An attribute definition has been parsed.
*/
typedef void (*attributeDeclSAXFunc)(void *ctx,
int type,
int def,
const xmlChar *defaultValue,
/**
* elementDeclSAXFunc:
* @ctx: the user data (XML parser context)
* @name: the element name
* @type: the element type
* @content: the element value tree
*
* An element definition has been parsed.
*/
typedef void (*elementDeclSAXFunc)(void *ctx,
int type,
/**
* unparsedEntityDeclSAXFunc:
* @ctx: the user data (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.
*/
typedef void (*unparsedEntityDeclSAXFunc)(void *ctx,
const xmlChar *notationName);
/**
* setDocumentLocatorSAXFunc:
* @ctx: the user data (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.
*/
typedef void (*setDocumentLocatorSAXFunc) (void *ctx,
/**
* startDocumentSAXFunc:
* @ctx: the user data (XML parser context)
*
* Called when the document start being processed.
*/
typedef void (*startDocumentSAXFunc) (void *ctx);
/**
* endDocumentSAXFunc:
* @ctx: the user data (XML parser context)
*
* Called when the document end has been detected.
*/
typedef void (*endDocumentSAXFunc) (void *ctx);
/**
* startElementSAXFunc:
* @ctx: the user data (XML parser context)
* @name: The element name, including namespace prefix
*
* Called when an opening tag has been processed.
*/
typedef void (*startElementSAXFunc) (void *ctx,
/**
* endElementSAXFunc:
* @ctx: the user data (XML parser context)
* @name: The element name
*
* Called when the end of an element has been detected.
*/
typedef void (*endElementSAXFunc) (void *ctx,
/**
* attributeSAXFunc:
* @ctx: the user data (XML parser context)
* @name: The attribute name, including namespace prefix
* @value: The attribute value
*
* Handle an attribute that has been read by the parser.
* The default handling is to convert the attribute into an
* DOM subtree and past it in a new xmlAttr element added to
* the element.
*/
typedef void (*attributeSAXFunc) (void *ctx,
/**
* referenceSAXFunc:
* @ctx: the user data (XML parser context)
* @name: The entity name
*
* Called when an entity reference is detected.
*/
typedef void (*referenceSAXFunc) (void *ctx,
/**
* charactersSAXFunc:
* @ctx: the user data (XML parser context)
* @ch: a xmlChar string
* @len: the number of xmlChar
*
* Receiving some chars from the parser.
*/
typedef void (*charactersSAXFunc) (void *ctx,
int len);
/**
* ignorableWhitespaceSAXFunc:
* @ctx: the user data (XML parser context)
* @ch: a xmlChar string
* @len: the number of xmlChar
*
* Receiving some ignorable whitespaces from the parser.
* UNUSED: by default the DOM building will use characters.
*/
typedef void (*ignorableWhitespaceSAXFunc) (void *ctx,
int len);
/**
* processingInstructionSAXFunc:
* @ctx: the user data (XML parser context)
* @target: the target name
* @data: the PI data's
*
* A processing instruction has been parsed.
*/
typedef void (*processingInstructionSAXFunc) (void *ctx,
/**
* commentSAXFunc:
* @ctx: the user data (XML parser context)
* @value: the comment content
*
* A comment has been parsed.
*/
typedef void (*commentSAXFunc) (void *ctx,
/**
* cdataBlockSAXFunc:
* @ctx: the user data (XML parser context)
* @value: The pcdata content
* @len: the block length
*
* Called when a pcdata block has been parsed.
*/
typedef void (*cdataBlockSAXFunc) (
void *ctx,
int len);
/**
* warningSAXFunc:
* @ctx: an XML parser context
* @...: extra parameters for the message display
*
* Display and format a warning messages, callback.
*/
const char *msg, ...);
/**
* errorSAXFunc:
* @ctx: an XML parser context
* @...: extra parameters for the message display
*
* Display and format an error messages, callback.
*/
const char *msg, ...);
/**
* fatalErrorSAXFunc:
* @ctx: an XML parser context
* @...: extra parameters for the message display
*
* Display and format fatal error messages, callback.
* Note: so far fatalError() SAX callbacks are not used, error()
* get all the callbacks for errors.
*/
const char *msg, ...);
/**
* isStandaloneSAXFunc:
* @ctx: the user data (XML parser context)
*
* Is this document tagged standalone?
*
* Returns 1 if true
*/
typedef int (*isStandaloneSAXFunc) (void *ctx);
/**
* hasInternalSubsetSAXFunc:
* @ctx: the user data (XML parser context)
*
* Does this document has an internal subset.
*
* Returns 1 if true
*/
typedef int (*hasInternalSubsetSAXFunc) (void *ctx);
/**
* hasExternalSubsetSAXFunc:
* @ctx: the user data (XML parser context)
*
* Does this document has an external subset?
*
* Returns 1 if true
*/
typedef int (*hasExternalSubsetSAXFunc) (void *ctx);
/************************************************************************
* *
* The SAX version 2 API extensions *
* *
************************************************************************/
/**
* XML_SAX2_MAGIC:
*
* Special constant found in SAX2 blocks initialized fields
*/
#define XML_SAX2_MAGIC 0xDEEDBEAF
/**
* startElementNsSAX2Func:
* @ctx: the user data (XML parser context)
* @localname: the local name of the element
* @prefix: the element namespace prefix if available
* @URI: the element namespace name if available
* @nb_namespaces: number of namespace definitions on that node
* @nb_attributes: the number of attributes on that node
* @nb_defaulted: the number of defaulted attributes. The defaulted
* ones are at the end of the array
* attribute values.
*
* SAX2 callback when an element start has been detected by the parser.
* It provides the namespace informations for the element, as well as
* the new namespace declarations on the element.
*/
typedef void (*startElementNsSAX2Func) (void *ctx,
int nb_namespaces,
const xmlChar **namespaces,
int nb_attributes,
int nb_defaulted,
const xmlChar **attributes);
/**
* endElementNsSAX2Func:
* @ctx: the user data (XML parser context)
* @localname: the local name of the element
* @prefix: the element namespace prefix if available
* @URI: the element namespace name if available
*
* SAX2 callback when an element end has been detected by the parser.
* It provides the namespace informations for the element.
*/
typedef void (*endElementNsSAX2Func) (void *ctx,
struct _xmlSAXHandler {
unsigned int initialized;
/* The following fields are extensions available only on version 2 */
void *_private;
};
/*
* SAX Version 1
*/
typedef struct _xmlSAXHandlerV1 xmlSAXHandlerV1;
typedef xmlSAXHandlerV1 *xmlSAXHandlerV1Ptr;
struct _xmlSAXHandlerV1 {
unsigned int initialized;
};
/**
* xmlExternalEntityLoader:
* @URL: The System ID of the resource requested
* @ID: The Public ID of the resource requested
* @context: the XML parser context
*
* External entity loaders types.
*
* Returns the entity input parser.
*/
const char *ID,
#ifdef __cplusplus
}
#endif
#include <libxml/encoding.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
*/
xmlInitParser (void);
xmlCleanupParser (void);
/*
* Input functions
*/
int len);
int len);
/*
* Basic parsing Interfaces
*/
#ifdef LIBXML_SAX1_ENABLED
xmlParseFile (const char *filename);
xmlParseMemory (const char *buffer,
int size);
#endif /* LIBXML_SAX1_ENABLED */
xmlKeepBlanksDefault (int val);
xmlPedanticParserDefault(int val);
xmlLineNumbersDefault (int val);
#ifdef LIBXML_SAX1_ENABLED
/*
* Recovery mode
*/
xmlRecoverMemory (const char *buffer,
int size);
xmlRecoverFile (const char *filename);
#endif /* LIBXML_SAX1_ENABLED */
/*
* Less common routines and SAX interfaces
*/
#ifdef LIBXML_SAX1_ENABLED
void *user_data,
const char *filename);
void *user_data,
const char *buffer,
int size);
int recovery);
const char *buffer,
int size,
int recovery);
const char *buffer,
int size,
int recovery,
void *data);
const char *filename,
int recovery);
const char *filename,
int recovery,
void *data);
const char *filename);
xmlParseEntity (const char *filename);
#endif /* LIBXML_SAX1_ENABLED */
#ifdef LIBXML_VALID_ENABLED
const xmlChar *ExternalID,
#endif /* LIBXML_VALID_ENABLE */
#ifdef LIBXML_SAX1_ENABLED
void *user_data,
int depth,
xmlNodePtr *lst);
#endif /* LIBXML_SAX1_ENABLED */
const char *data,
int datalen,
int options,
xmlNodePtr *lst);
#ifdef LIBXML_SAX1_ENABLED
void *user_data,
int depth,
int recover);
void *user_data,
int depth,
xmlNodePtr *lst);
#endif /* LIBXML_SAX1_ENABLED */
xmlNodePtr *lst);
/*
* Parser contexts handling.
*/
xmlNewParserCtxt (void);
#ifdef LIBXML_SAX1_ENABLED
const char *filename);
#endif /* LIBXML_SAX1_ENABLED */
#ifdef LIBXML_LEGACY_ENABLED
/*
*/
xmlGetFeaturesList (int *len,
const char **result);
const char *name,
void *result);
const char *name,
void *value);
#endif /* LIBXML_LEGACY_ENABLED */
#ifdef LIBXML_PUSH_ENABLED
/*
* Interfaces for the Push mode.
*/
void *user_data,
const char *chunk,
int size,
const char *filename);
const char *chunk,
int size,
int terminate);
#endif /* LIBXML_PUSH_ENABLED */
/*
* Special I/O mode.
*/
void *user_data,
void *ioctx,
/*
* Node infos.
*/
const xmlNodePtr node);
const xmlNodePtr node);
const xmlParserNodeInfoPtr info);
/*
* External entities handling actually implemented in xmlIO.
*/
xmlGetExternalEntityLoader(void);
xmlLoadExternalEntity (const char *URL,
const char *ID,
/*
* Index lookup, actually implemented in the encoding module
*/
/*
*/
/**
* xmlParserOption:
*
* This is the set of XML parser options that can be passed down
* to the xmlReadDoc() and similar calls.
*/
typedef enum {
the tree allowed afterwards (will possibly
crash if you try to modify the tree) */
const char *chunk,
int size,
const char *filename,
const char *encoding);
int options);
const char *URL,
const char *encoding,
int options);
xmlReadFile (const char *URL,
const char *encoding,
int options);
xmlReadMemory (const char *buffer,
int size,
const char *URL,
const char *encoding,
int options);
const char *URL,
const char *encoding,
int options);
void *ioctx,
const char *URL,
const char *encoding,
int options);
const char *URL,
const char *encoding,
int options);
const char *filename,
const char *encoding,
int options);
const char *buffer,
int size,
const char *URL,
const char *encoding,
int options);
int fd,
const char *URL,
const char *encoding,
int options);
void *ioctx,
const char *URL,
const char *encoding,
int options);
/*
* Library wide options
*/
/**
* xmlFeature:
*
* Used to examine the existance of features that can be enabled
* or disabled at compile-time.
* They used to be called XML_FEATURE_xxx but this clashed with Expat
*/
typedef enum {
XML_WITH_THREAD = 1,
XML_WITH_TREE = 2,
XML_WITH_OUTPUT = 3,
XML_WITH_PUSH = 4,
XML_WITH_READER = 5,
XML_WITH_PATTERN = 6,
XML_WITH_WRITER = 7,
XML_WITH_SAX1 = 8,
XML_WITH_FTP = 9,
XML_WITH_HTTP = 10,
XML_WITH_VALID = 11,
XML_WITH_HTML = 12,
XML_WITH_LEGACY = 13,
XML_WITH_C14N = 14,
XML_WITH_CATALOG = 15,
XML_WITH_XPATH = 16,
XML_WITH_XPTR = 17,
XML_WITH_XINCLUDE = 18,
XML_WITH_ICONV = 19,
XML_WITH_ISO8859X = 20,
XML_WITH_UNICODE = 21,
XML_WITH_REGEXP = 22,
XML_WITH_AUTOMATA = 23,
XML_WITH_EXPR = 24,
XML_WITH_SCHEMAS = 25,
XML_WITH_SCHEMATRON = 26,
XML_WITH_MODULES = 27,
XML_WITH_DEBUG = 28,
XML_WITH_DEBUG_MEM = 29,
XML_WITH_DEBUG_RUN = 30,
XML_WITH_ZLIB = 31,
} xmlFeature;
#ifdef __cplusplus
}
#endif
#endif /* __XML_PARSER_H__ */