暂时保存

1、access函数:检查文件是否存在
2、sleep函数  睡眠多久
3、xmlDocPtr xml文件解析相关
4、xmlParseFile 加载xml文件内容
示例:
xmlDocPtr xml_conf_doc = (xmlDocPtr)NULL;
xml_conf_doc = xmlParseFile (CONF_XML_FILE);
if (NULL == xml_conf_doc)
{
      NETCARD_ERRLOG("Parse xml %s failed, maybe hms start firstly\n", CONF_XML_FILE);
      return;
}

<pre name="code" class="plain">__FUNCTION__表示函数名,
__LINE__表示在第几行

__FILE__ 包含前程序文件名字符串
__LINE__  表示前行号整数
__DATE__ 包含前期字符串
__STDC__  编译器遵循ANSI C标准非零值
__TIME__ 包含前间字符串


errno:错误代码


INET_ADDRSTRLEN
INET6_ADDRSTRLEN

int read_xml_file (const xmlDoc * doc_ptr, const char *xpath, char *buf)
{
    int ret_int_num = HMS_FAIL;
    xmlChar *content = (xmlChar *)NULL;
    xmlXPathContextPtr xpathCtx = (xmlXPathContextPtr)NULL;
    xmlXPathObjectPtr xpathObj = (xmlXPathObjectPtr)NULL;

    if(NULL == xpath || NULL == buf || NULL == doc_ptr)
    {
        TOOLSPRINT("parameter error\n");
        goto cleanup;
    }

    /* Create point the xml_doc and malloc memory space */
    xpathCtx = xmlXPathNewContext ((xmlDocPtr)doc_ptr);
    if (NULL == xpathCtx)
    {
        TOOLSPRINT("Error: unable to create new XPath context\n");
        goto cleanup;
    }

    /* Evaluate xpath expression */
    xpathObj = xmlXPathEval ((xmlChar *)xpath, xpathCtx);
    if ((NULL == xpathObj) || (NULL == xpathObj->nodesetval))
    {
        goto cleanup;
    }

    /* dispose the node list */
    if (!xpathObj->nodesetval->nodeNr)
    {
        /*HMS_RPRINT(HMS_LOG_DEBUG, "Error: Node not found!\n");*/
        goto cleanup;
    }

     /* dispose the nodeTab[0]==NULL mode */
    if (NULL == xpathObj->nodesetval->nodeTab[0])
    {
        TOOLSPRINT("Error: Node content is NULL!\n");
        goto cleanup;
    }

    content = xmlNodeGetContent (xpathObj->nodesetval->nodeTab[0]);
    if (NULL == content)
    {
        goto cleanup;
    }

    if (MAX_NODE_VALUE_SIZE <=  strlen ((char *)content))
    {
        TOOLSPRINT("The node's content is too large\n");
        goto cleanup;
    }

    if (0 == strlen ((char *)content))
    {
        TOOLSPRINT("The node's content inexistence\n");
        goto cleanup;
    }

    snprintf (buf, MAX_NODE_VALUE_SIZE, "%s", (char *)content);
    ret_int_num = HMS_SUCCESS;

cleanup:
    if (NULL != content)
    {
        xmlFree (content);
    }

    if (NULL != xpathObj)
    {
        xmlXPathFreeObject (xpathObj);
    }

    if (NULL != xpathCtx)
    {
        xmlXPathFreeContext (xpathCtx);
    }

    return (ret_int_num);
}


 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值