📄 nxml.h
字号:
/* nXml - Copyright (C) 2005 bakunin - Andrea Marchesini * <bakunin@autistici.org> * * This source code is free software; you can redistribute it and/or * modify it under the terms of the GNU Public License as published * by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * This source code is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * Please refer to the GNU Public License for more details. * * You should have received a copy of the GNU Public License along with * this source code; if not, write to: * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#ifndef __N_XML_H__#define __N_XML_H__//#include <curl/curl.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <stdarg.h>#include <stdlib.h>#include <stdio.h>#include <string.h>#include <errno.h>#ifdef __cplusplusextern "C" {#endiftypedef struct nxml_t nxml_t;typedef struct nxml_data_t nxml_data_t;typedef struct nxml_attr_t nxml_attr_t;typedef struct nxml_doctype_t nxml_doctype_t;typedef struct nxml_namespace_t nxml_namespace_t;typedef struct __nxml_doctype_notation_t __nxml_doctype_notation_t;typedef struct __nxml_doctype_element_t __nxml_doctype_element_t;typedef struct __nxml_doctype_element_content_t __nxml_doctype_element_content_t;typedef struct __nxml_doctype_attribute_t __nxml_doctype_attribute_t;typedef struct __nxml_doctype_attribute_attdef_t __nxml_doctype_attribute_attdef_t;typedef struct __nxml_doctype_attribute_attdef_list_t __nxml_doctype_attribute_attdef_list_t;typedef struct __nxml_doctype_entity_t __nxml_doctype_entity_t;typedef struct __nxml_private_t __nxml_private_t;/** This enum describes the error type of libnxml */typedef enum{ NXML_OK = 0, /**< No error */ NXML_ERR_POSIX, /**< For the correct error, use errno */ NXML_ERR_PARSER, /**< Parser error */ NXML_ERR_DATA /**< The parameters are incorrect */} nxml_error_t;/** This enum describes the type of data element of libnxml */typedef enum{ NXML_TYPE_TEXT, /**< Text element */ NXML_TYPE_COMMENT, /**< Comment element */ NXML_TYPE_ELEMENT, /**< Data element */ NXML_TYPE_PI, /**< PI element */ NXML_TYPE_ELEMENT_CLOSE, /**< Data element - For internal use only */} nxml_type_t;/** This enum describes the supported XML version */typedef enum{ NXML_VERSION_1_1, /**< XML 1.1 */ NXML_VERSION_1_0 /**< XML 1.0 */} nxml_version_t;/** This enum describes the CharSet of XML document */typedef enum { NXML_CHARSET_UTF8, /**< UTF8 chatset detected */ NXML_CHARSET_UTF16LE, /**< UTF 16 Little Endian detected */ NXML_CHARSET_UTF16BE, /**< UTF 16 Big Endian detected */ NXML_CHARSET_UCS4_1234, /**< UCS 4byte order 1234 detected */ NXML_CHARSET_UCS4_4321, /**< UCS 3byte order 4321 detected */ NXML_CHARSET_UCS4_2143, /**< UCS 3byte order 2143 detected */ NXML_CHARSET_UCS4_3412, /**< UCS 3byte order 3412 detected */ NXML_CHARSET_UNKNOWN /**< Unknown format */} nxml_charset_t;#define NXML_DOCTYPEFLAG_NOFLAG 0x0 /**< No flag */#define NXML_DOCTYPEFLAG_DOWNLOAD 0x1 /**< Download the document */#define NXML_DOCTYPEFLAG_RECURSIVE 0x2 /**< Do it recursive *//** This enum describes the type of element for the doctype parsing. * It is for internal use only */typedef enum { NXML_DOCTYPE_ELEMENT_EMPTY, NXML_DOCTYPE_ELEMENT_ANY, NXML_DOCTYPE_ELEMENT_MIXED_OR_CHILDREN,} __nxml_doctype_element_type_t;typedef enum { NXML_DOCTYPE_ELEMENT_CONTENT_ONE = 0, NXML_DOCTYPE_ELEMENT_CONTENT_0_OR_1, NXML_DOCTYPE_ELEMENT_CONTENT_0_OR_MORE, NXML_DOCTYPE_ELEMENT_CONTENT_1_OR_MORE} __nxml_doctype_element_content_type_t;typedef enum { NXML_DOCTYPE_ATTRIBUTE_TYPE_ENUMERATION, NXML_DOCTYPE_ATTRIBUTE_TYPE_NOTATION, NXML_DOCTYPE_ATTRIBUTE_TYPE_CDATA, NXML_DOCTYPE_ATTRIBUTE_TYPE_ID, NXML_DOCTYPE_ATTRIBUTE_TYPE_IDREF, NXML_DOCTYPE_ATTRIBUTE_TYPE_IDREFS, NXML_DOCTYPE_ATTRIBUTE_TYPE_ENTITY, NXML_DOCTYPE_ATTRIBUTE_TYPE_ENTITIES, NXML_DOCTYPE_ATTRIBUTE_TYPE_NMTOKEN, NXML_DOCTYPE_ATTRIBUTE_TYPE_NMTOKENS,} __nxml_doctype_attribute_attdef_type_t;typedef enum { NXML_DOCTYPE_ATTRIBUTE_VALUE_ANY, NXML_DOCTYPE_ATTRIBUTE_VALUE_REQUIRED, NXML_DOCTYPE_ATTRIBUTE_VALUE_IMPLIED, NXML_DOCTYPE_ATTRIBUTE_VALUE_FIXED} __nxml_doctype_attribute_attdef_value_t;/** Data struct for any element of XML stream * * \brief * Data struct for any element of XML streams/files */struct nxml_data_t{ nxml_type_t type; /**< type of this nxml_data_t struct */ char *value; /**< The value of this data struct */ nxml_attr_t *attributes; /**< List of attributes of this struct. This list exists only if type == NXML_TYPE_ELEMENT */ nxml_namespace_t *ns; /**< Pointer to the correct namespace */ nxml_namespace_t *ns_list; /**< The namespaces in this element */ nxml_data_t *children; /**< The children of this data struct */ nxml_data_t *next; /**< The next element */ nxml_data_t *parent; /**< The parent */ nxml_t *doc; /**< The nxml_t */};/** Data struct for any element of attribute of xml element * * \brief * Data struct for any element of attribute of xml element */struct nxml_attr_t{ char *name; char *value; nxml_namespace_t *ns; nxml_attr_t *next;};/** Data struct for doctype elements * * \brief * Data struct for doctype elements */struct nxml_doctype_t{ char *value; /**< The string no parsers */ char *name; /**< The name of current doctype */ nxml_t *doc; /**< The nxml_t */ nxml_doctype_t *next; /** This information will be set only after a nxml_valid_dtd(...) */ char *system_literal; /**< If the DTD has a system_leteral */ char *pubid_literal; /**< If the DTD has a system_leteral */};/** Data struct private for doctype parsing of contents of a element * * \brief * Data struct private for doctype parsing of contents of a element */struct __nxml_doctype_element_content_t { char *name; int pcdata; int choose; __nxml_doctype_element_content_type_t type; __nxml_doctype_element_content_t *list; __nxml_doctype_element_content_t *next;};/** Data struct private for doctype parsing of elements * * \brief * Data struct private for doctype parsing of elements */struct __nxml_doctype_element_t { char *name; __nxml_doctype_element_content_t *content; __nxml_doctype_element_type_t type; __nxml_doctype_element_t *next;};/** Data struct for any element of attribute of xml element * * \brief * Data struct for any element of attribute of xml element */struct __nxml_doctype_attribute_attdef_list_t{ char *value; __nxml_doctype_attribute_attdef_list_t *next;};/** Data struct private for doctype parsing of attdefs of a attribute * * \brief * Data struct private for doctype parsing of attdefs of a attribute */struct __nxml_doctype_attribute_attdef_t { char *name; __nxml_doctype_attribute_attdef_type_t type; __nxml_doctype_attribute_attdef_value_t value; char *fixed_value; __nxml_doctype_attribute_attdef_list_t *list; __nxml_doctype_attribute_attdef_t *next;};/** Data struct private for doctype parsing of attributes * * \brief * Data struct private for doctype parsing of attributes */struct __nxml_doctype_attribute_t { char *element; __nxml_doctype_attribute_attdef_t *attdef; __nxml_doctype_attribute_t *next;};/** Data struct private for doctype parsing of entities * * \brief * Data struct private for doctype parsing of entities */struct __nxml_doctype_entity_t { int percent; char *name; char *reference; char *system; char *pubid; char *ndata; __nxml_doctype_entity_t *next;};/** Data struct private for doctype parsing of notations * * \brief * Data struct private for doctype parsing of notations */struct __nxml_doctype_notation_t { char *system_literal; char *pubid_literal; __nxml_doctype_notation_t *next;};/** Data struct for namespace * * \brief * Data struct for namespace */struct nxml_namespace_t { char *prefix; char *ns; nxml_namespace_t *next;};/** Data struct private for internal use only * * \brief * Data struct private for internal use only */struct __nxml_private_t{ void (*func) (char *, ...); int line; int timeout; __nxml_doctype_element_t *elements; __nxml_doctype_attribute_t *attributes; __nxml_doctype_entity_t *entities; __nxml_doctype_notation_t *notations;};/** Principal data struct. It contains pointers to any other structures. * * \brief * Principal data struct. It contains pointers to any other structures */struct nxml_t{ char *file; /**< XML document filename or url */ size_t size; /**< Size of XML document in byte */ nxml_version_t version; /**< XML document version */ int standalone; /**< This document is standalone ? */ char *encoding; /**< Encoding type */ nxml_charset_t charset_detected; /**< charset detected when the a XML document is parsed. The document will be convert to UTF-8 */ nxml_data_t *data; /**< The data of XML document */ nxml_doctype_t *doctype; /**< The doctype of XML document */ __nxml_private_t priv; /**< For internal use only */};/* INIT FUNCTIONS ************************************************************//** * This function creates a new nxml_t element. * * \param nxml Pointer to a nxml_t element. It will be allocted. * \return the error code */nxml_error_t nxml_new (nxml_t ** nxml);/** * This function creates a new nxml_data_t child of a parent in the data * struct. If parent is NULL the child will be created in the root level * of XML document. * * \param nxml Pointer to a nxml_t data struct. * \param parent The parent of new data struct child. If it is NULL, the * child is in the root level. * \param child It is the pointer to the new data struct. If *child is NULL, * it will be allocated, else it will be insert as it is. * \return the error code
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -