Files
microser/include/xmltools.h

146 lines
3.9 KiB
C
Raw Permalink Normal View History

2025-01-16 16:17:01 +08:00
/**
* @file xmltools.h
* @brief <EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>XML<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿ<EFBFBD>
*
* @version $Revision: 1.1 $
* @date $Date: 2018/11/24 06:54:50 $
* @author $Author: lizhongming $
* @state $State: Exp $
*
*/
#ifndef _XMLTOOLS_H
#define _XMLTOOLS_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "utf.h"
typedef int (*db_parser_handler)(char* buf,void* object,void* rdb);
typedef int (dbparser_fn_t)(char* buf,void* object,void* rdb);
/** Skip unused part of xml
* set skip tag and the levels,
* when the end tag handler encounters the same depth , the
* skipped element has ended and the flag be cleared!
* assuming {root}=1 ,skip flag and skip depth
*/
typedef struct xml_parse_skip_t xml_parse_skip_t;
struct xml_parse_skip_t{
int skip_flag; /**< is skip */
int skip_depth; /**< which level of the depth */
int global_depth;/**< {root}=1 */
};
#define XML_TOOLS_ATTR_AND (1) //attr is and relation
#define XML_TOOLS_ATTR_OR (2) //attr is or-relation
#define XMLTOOLS_MAX_PATH_LEN (10) //<2F><><EFBFBD><EFBFBD>֧<EFBFBD><D6A7>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define XMLTOOLS_MAX_VALUE_LEN (64) //<2F><><EFBFBD><EFBFBD>ֵ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFB3A4>
#define XMLTOOLS_MAX_TAG_LEN (32) //<2F><>ǩ<EFBFBD><C7A9><EFBFBD><EFBFBD>
#define XMLTOOLS_MAX_NAME XMLTOOLS_MAX_TAG_LEN
#define XMLTOOLS_MAX_ATTR_LEN (3) //max 3 attrs
typedef char** elem_text ;
typedef struct path_session_t path_session_t;
typedef struct attr_pair attr_pair;
struct attr_pair{
char name[XMLTOOLS_MAX_NAME];
char value[XMLTOOLS_MAX_TAG_LEN];
};
typedef enum type_identifier_e type_identifier_e;
enum type_identifier_e{
axis_child,
axis_attribute,
predicate
};
/** contains one seesion of xpath*/
struct path_session_t
{
type_identifier_e type_identifier;
char tag[XMLTOOLS_MAX_TAG_LEN]; /**< */
attr_pair attrs[XMLTOOLS_MAX_ATTR_LEN]; /**< ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĺ<EFBFBD>ϵ */
//attr_pair * current;//current position of attr_pair ,used internal
int level; /**< desired level, root elem is 1*/
};
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief ͨ<EFBFBD><EFBFBD>һ<EFBFBD>α<EFBFBD><EFBFBD><EFBFBD>XML<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȡijһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ȫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* @param filename XML<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param path element·<EFBFBD><EFBFBD>
* @param item element<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param output_data <EFBFBD><EFBFBD><EFBFBD><EFBFBD>element<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD> APR_SUCCESS - <EFBFBD>ɹ<EFBFBD>
* APR_NOTFOUND - element<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* APR_EBADF - <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
APR_DECLARE(int) xml_db_attach(const char* filename,const char* path,
const char* item, db_parser_handler pfn,void* output_data);
/**
* @brief <EFBFBD><EFBFBD>ȡXML<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD><EFBFBD><EFBFBD>element<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* @param filename XML<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param path elementȫ·<EFBFBD><EFBFBD>
* @param value <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD>element<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD> APR_SUCCESS - <EFBFBD>ɹ<EFBFBD>
* APR_NOTFOUND - element<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* APR_EBADF - <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @note
<pre>Example:
char *value = NULL;
rv= xml_get_elem("SYSCONF.xml","//systemconf/IPBCASTB/", &value);
//Example:
//<systemconf>
// <VERSION type="386">1.0</VERSION>
// <IPBCASTB > 172.20.255.255 </IPBCASTB>
//</systemconf>
//
//<2F><><EFBFBD><EFBFBD>XPATH<54>
//axis-identifier::node-test[predicate1][predicate2]..
//rv=xml_get_elem("SYSCONF.xml","//systemconf/IPBCASTB/", &value);
value=" 172.20.255.255 "
//rv=xml_get_elem("SYSCONF.xml","//systemconf/VERSION/@type/", &value);
value="386"
//rv=xml_get_elem("SYSCONF.xml","//systemconf/VERSION[attribute::type="386"]/", &value);
value="1.0"
//ע<><D7A2>Ŀǰν<C7B0><CEBD>ֻ֧<D6BB><D6A7>=<3D>ţ<EFBFBD>ֻ֧<D6BB><D6A7>attribute<74><65>,ֻ֧<D6BB><D6A7>1<EFBFBD><31>ν<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ʽ<EFBFBD><CABD>
</pre>
*/
APR_DECLARE(int) xml_get_elem(const char* filename,const char* path, char **value);
/**
* @brief dbparser_fn_retrieve
* @param fn_name Ҫȡ<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
APR_DECLARE(dbparser_fn_t*) dbparser_fn_retrieve(const char *fn_name);
/**
* @brief dbparser_fn_register
* @param fn_name Ҫע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param pfn <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
APR_DECLARE(void) dbparser_fn_register(const char *fn_name,dbparser_fn_t *pfn, apr_pool_t *pool);
APR_DECLARE(int) xml_get_elem_free_memory(void *point);
#ifdef __cplusplus
}
#endif
#endif /* _XMLTOOLS_H */