parser.h

Estructura xmlParserCtxt

Contexto del analizador XML.

Sintaxis

/**
 * 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.
 */
typedef struct _xmlParserCtxt xmlParserCtxt;
typedef xmlParserCtxt *xmlParserCtxtPtr;

struct _xmlParserCtxt {
    struct _xmlSAXHandler *sax;       /* The SAX handler */
    void            *userData;        /* For SAX interface only, used by DOM build */
    xmlDocPtr           myDoc;        /* the document being built */
    int            wellFormed;        /* is the document well formed */
    int       replaceEntities;        /* shall we replace entities ? */
    const xmlChar    *version;        /* the XML version string */
    const xmlChar   *encoding;        /* the declared encoding, if any */
    int            standalone;        /* standalone document */
    int                  html;        /* an HTML(1)/Docbook(2) document
                                       * 3 is HTML after <head>
                                       * 10 is HTML after <body>
                                       */

    /* Input stream stack */
    xmlParserInputPtr  input;         /* Current input stream */
    int                inputNr;       /* Number of current input streams */
    int                inputMax;      /* Max number of input streams */
    xmlParserInputPtr *inputTab;      /* stack of inputs */

    /* Node analysis stack only used for DOM building */
    xmlNodePtr         node;          /* Current parsed Node */
    int                nodeNr;        /* Depth of the parsing stack */
    int                nodeMax;       /* Max depth of the parsing stack */
    xmlNodePtr        *nodeTab;       /* array of nodes */

    int record_info;                  /* Whether node info should be kept */
    xmlParserNodeInfoSeq node_seq;    /* info about each node parsed */

    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 ? */
    xmlValidCtxt        vctxt;        /* The validity context */

    xmlParserInputState instate;      /* current type of input */
    int                 token;        /* next char look-ahead */

    char           *directory;        /* the data directory */

    /* Node name stack */
    const xmlChar     *name;          /* Current parsed Node */
    int                nameNr;        /* Depth of the parsing stack */
    int                nameMax;       /* Max depth of the parsing stack */
    const xmlChar *   *nameTab;       /* array of nodes */

    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 */
    const xmlChar *    intSubName;    /* name of subset */
    xmlChar *          extSubURI;     /* URI of external subset */
    xmlChar *          extSubSystem;  /* SYSTEM ID of external 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 */
    xmlParserInputPtr  entity;        /* used to check entities boundaries */
    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 */
    xmlDictPtr         dict;          /* dictionnary for the parser */
    const xmlChar *   *atts;          /* array for the attributes callbacks */
    int                maxatts;       /* the size of the array */
    int                docdict;       /* use strings from dict to build tree */

    /*
     * pre-interned strings
     */
    const xmlChar *str_xml;
    const xmlChar *str_xmlns;
    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 */
    const xmlChar *   *nsTab;         /* the array of prefix/namespace name */
    int               *attallocs;     /* which attribute were allocated */
    void *            *pushTab;       /* array of data for push */
    xmlHashTablePtr    attsDefault;   /* defaulted attributes if any */
    xmlHashTablePtr    attsSpecial;   /* non-CDATA attributes if any */
    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 */
    xmlNodePtr        freeElems;    /* List of freed element nodes */
    int               freeAttrsNr;  /* number of freed attributes nodes */
    xmlAttrPtr        freeAttrs;    /* List of freed attributes nodes */

    /*
     * the complete error informations for the last error.
     */
    xmlError          lastError;
    xmlParserMode     parseMode;    /* the parser mode */
    unsigned long    nbentities;    /* number of entities references */
    unsigned long  sizeentities;    /* size of parsed entities */

    /* for use by HTML non-recursive parser */
    xmlParserNodeInfo *nodeInfo;      /* Current NodeInfo */
    int                nodeInfoNr;    /* Depth of the parsing stack */
    int                nodeInfoMax;   /* Max depth of the parsing stack */
    xmlParserNodeInfo *nodeInfoTab;   /* array of nodeInfos */

    int                input_id;      /* we need to label inputs */
    unsigned long      sizeentcopy;   /* volume of entity copy */
};

En tree.h están definidos los tipos:

typedef struct _xmlParserCtxt xmlParserCtxt;
typedef xmlParserCtxt *xmlParserCtxtPtr;

Miembros

sax
Puntero a una estructura xmlSAXHandler con el manipulador SAX.
userData
Puntero genérico a datos de usuario solo para el interfaz SAX.
myDoc
Puntero a estructura xmlDoc con el documento que se está construyendo.
wellFormed
Indica si el documento está bien formado.
replaceEntities
Indica si se deben reemplazar las entidades.
version
Cadena xmlChar con la versión XML.
encoding
Cadena xmlChar con la codificación declarada, si la hay.
standalone
Indica si se trada de un documento independiente.
html
Un documento HTML(1), Docbook(2), 3 es HTML después de <head>, 10 es HTML después de <body>.

Pila de stream de entrada:

input
Puntero a estructura xmlParserInput al stream de entrada actual.
inputNr
Número de streams de entrada actual.
inputMax
Número máximo de streams de entrada.
inputTab
Array de punteros xmlParserInput con la pila de entradas.

La pila de análisis de nodos solo utilizada para la construcción de DOM:

node
Puntero a estructura xmlNode al nodo analizado actualmente.
nodeNr
Profundidad de la pila de análisis.
nodeMax
Profundidad máxima de la pila de análisis.
nodeTab
Array de punteros a estructuras xmlNode.
record_info
Indica si se debe conservar la información del nodo.
node_seq
Estructura xmlParserNodeInfoSeq con la información sobre cada nodo analizado.
errNo
Código de error.
hasExternalSubset
Referencia y subconjunto externo.
hasPErefs
Indica si el subconjunto interno tiene referencias PE.
external
Indica si estamos analizando una entidad externa.
valid
Indica si el documento es válido.
validate
Indica si debemos intentar validar.
vctxt
Estructura xmlValidCtxt con el contexto de validez.
instate
Estructura xmlParserInputState con el tipo actual de entrada.
token
Próxima mirada al carácter.
directory
Puntero a char con los datos del directorio.

Pila de nombres de nodos:

name
Cadena de xmlChar al nodo analizado actualmente.
nameNr
Profundidad de la pila de análisis.
nameMax
Profundidad máxima de la pila de análisis.
nameTab
Array de nombres de nodos.
nbChars
Número de xmlChar procesados.
checkIndex
Usado por la búsqueda progresiva de análisis sintáctico.
keepBlanks
Indica si se deben mantener los espacios. Feo pero ...
disableSAX
Indica si las retrollamadas SAX están deshabilitadas.
inSubset
Indica si el análisis es en el interior del subconjunto 1, o en el exterior 2.
intSubName
Nombre del subconjunto.
extSubURI
URI del subconjunto externo.
extSubSystem
ID SYSTEM del subconjunto externo.

Valores xml:space:

space
Indica si el analizador sintáctico debe conservar los espacios. (Puede ser otra cosa, ya que se trata de un puntero.
spaceNr
Profundidad de la pila de análisis.
spaceMax
Profundidad máxima de la pila de análisis.
spaceTab
Array de informaciones de espacios.
depth
Para evitar bucles de sustituciones de entidades.
entity
Puntero a estructura xmlParserInput usada para verificar los contornos de las entidades.
charset
Codificación real del contenido en memoria codificación de una xmlCharEncoding.
nodelen
Este campo y el siguiente están ahí para acelerar el análisis de los nodos grandes.
nodemem
Este campos y el anterior están ahí para acelerar el análisis de los nodos grandes.
pedantic
Indica advertencias pedantes.
_private
Para datos del usuario, libxml no lo utiliza.
loadsubset
Indica si se debe cargar el subconjunto externo.
linenumbers
Establecer el número de línea en el contenido del elemento.
catalogs
Catálogo propio del documento.
recovery
Ejecutar en modo de recuperación.
progressive
Indica si es un análisis progresivo.
dict
Puntero a estructura xmlDict con el diccionario para el analizador.
atts
Array para las retrollamadas de los atributos.
maxatts
Tamaño del array.
docdict
Indica si se deben usar las cadenas del diccionario para construir el árbol.

Cadenas preinternadas.

str_xml
str_xmlns
str_xml_ns

Usados solo para el nuevo modo SAX:

sax2
Indica si se está operando en el nuevo modo SAX.
nsNr
Número de espacios de nombres heredados.
nsMax
Tamaño de los arrays.
nsTab
Array de prefijos/nombres de espacios con nombre.
attallocs
Qué atributo se asignó.
pushTab
Array de datos para el push.
attsDefault
Array de xmlHashTable con los atributos por defecto, si hay.
attsSpecial
Array de xmlHashTable con los atributos no CDATA por defecto, si hay.
nsWellFormed
Indica si el Namespace del documento es correcto.
options
Opciones extra.

Estos campos solo son necesarios para el análisis sintáctico del flujo de datos:

dictNames
Usar los nombres del diccionario para el árbol.
freeElemsNr
Número de nodos de elementos liberados.
freeElems
Lista de xmlNode con los nodos de elementos liberados.
freeAttrsNr
Número de nodos de atributos liberados.
freeAttrs
Lista de xmlAttr con los nodos de atributos liberados.

Información completa del último error:

lastError
Código del último error.
parseMode
El modo del analizador.
nbentities
Número de referencias de entidades.
sizeentities
Tamaño de las entidades analizadas.

Usado por el analizador HTML no recursivo:

nodeInfo
Puntero a xmlParserNodeInfo con la información de nodo actual.
nodeInfoNr
Profundidad de la pila de análisis.
nodeInfoMax
Máxima profundidad de la pila de análisis.
nodeInfoTab
Array de estructuras xmlParserNodeInfo con informaciones de nodos.
input_id
Indica si se necesita etiquetar las entradas.
sizeentcopy
Volumen de la copia de la entidad.