#include "StdAfx.h"
#include "parse.h"
#include <string>
#include "stdafx.h"
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <iostream>
#include <libxml/xpath.h>
#include <libxml/xpathInternals.h>
#include <stdio.h>
#include <stdlib.h>
#include<windows.h>
using namespace std
parse::parse()
//int parse::parsexml()
{
xmlDocPtr doc //定义解析文档指针
xmlNodePtr curNode //定义结点指针(你需要它为了在各个结点间移动)
xmlChar *szKey //临时字符串变量
char *szDocName
doc = xmlReadFile("SimACQ_Config.xml","GB2312",XML_PARSE_RECOVER)//解析文件
//检查解析文档是否成功,如果不成功,libxml将指一个注册的错误并停止。
if (NULL==doc)
{
fprintf(stderr,"Document not parsed successfully. /n")
/*return -1*/
}
curNode = xmlDocGetRootElement(doc)//确定文档根元素
/*检查确认当前文档中包含内容*/
if (NULL == curNode)
{
fprintf(stderr,"empty document/n")
xmlFreeDoc(doc)
/*return -1*/
}
/*在这个例子中,我们需要确认文档是正确的类型。“root”是在这个示例中使用文档的根类型。*/
if (xmlStrcmp(curNode->name, BAD_CAST "SIMCONFIG"))
{
fprintf(stderr,"document of the wrong type, root node != mail")
xmlFreeDoc(doc)
/*return -1*/
}
curNode = curNode->xmlChildrenNode
xmlNodePtr propNodePtr = curNode
while(curNode != NULL)
{
//取出节点中的内容
if ((!xmlStrcmp(curNode->name, (const xmlChar *)"ComConfig")))
{
xmlNodePtr comConfigPtr= curNode->children
while(comConfigPtr!=NULL)
{
if((!xmlStrcmp(comConfigPtr->name,(const xmlChar *)"DMS")))
{
xmlChar* szAttr = xmlGetProp(comConfigPtr,BAD_CAST "IP")
IP=(char*)szAttr
szAttr=xmlGetProp(comConfigPtr,BAD_CAST "PORT")
PORT=atoi((const char *)szAttr)
szAttr=xmlGetProp(comConfigPtr,BAD_CAST "TIMEOUT")
TIMEOUT=atoi((const char *)szAttr)
xmlFree(szAttr)
}
comConfigPtr=comConfigPtr->next
}
}
if ((!xmlStrcmp(curNode->name, (const xmlChar *)"Log")))
{
xmlChar* szAttr = xmlGetProp(curNode,BAD_CAST "Flag")
if(szAttr!=NULL)
{
if((!xmlStrcmp(szAttr,(const xmlChar *)"True")))
{
FLAG=true
}
else
{
FLAG=false
}
}
szAttr = xmlGetProp(curNode,BAD_CAST "Path")
if(szAttr!=NULL)
{
PATH=(char*)szAttr
}
xmlFree(szAttr)
}
if ((!xmlStrcmp(curNode->name, (const xmlChar *)"DMS")))
{
xmlChar* szAttr = xmlGetProp(curNode,BAD_CAST "Cache")
if(szAttr!=NULL)
{
Cache=atoi((const char *)szAttr)
}
xmlFree(szAttr)
}
if ((!xmlStrcmp(curNode->name, (const xmlChar *)"SimFile")))
{
xmlChar* szAttr = xmlGetProp(curNode,BAD_CAST "Type")
if(szAttr!=NULL)
{
if((!xmlStrcmp(szAttr,(const xmlChar *)"PlainFilm")))
{
xmlNodePtr FileNodes=curNode->children
int i=0
while(FileNodes!=NULL)
{
if((!xmlStrcmp(FileNodes->name,(const xmlChar *)"FILE")))
{
szAttr = xmlGetProp(FileNodes,BAD_CAST "name")
if(szAttr!=NULL)
{
/*SIM_PLAIN[i].Name=(char*)szAttr*/
strcpy(simulation.SIM_PLAIN[i].Name,(char*)szAttr)
}
szAttr=xmlGetProp(FileNodes,BAD_CAST "sliceNum")
if(szAttr!=NULL)
{
simulation.SIM_PLAIN[i].Num=atoi((char*)szAttr)
}
i++
}
FileNodes=FileNodes->next
}
xmlFree(FileNodes)
simulation.SIM_PLAIN[i].flag=0
}
if((!xmlStrcmp(szAttr,(const xmlChar *)"Spiral"))){
xmlNodePtr FileNodes=curNode->children
int i=0
while(FileNodes!=NULL)
{
if((!xmlStrcmp(FileNodes->name,(const xmlChar *)"FILE")))
{
szAttr = xmlGetProp(FileNodes,BAD_CAST "name")
if(szAttr!=NULL)
{
/*SIM_SPIRAL[i].Name=(char*)szAttr*/
strcpy(simulation.SIM_SPIRAL[i].Name,(char*)szAttr)
}
szAttr=xmlGetProp(FileNodes,BAD_CAST "sliceNum")
if(szAttr!=NULL)
{
simulation.SIM_SPIRAL[i].Num=atoi((char*)szAttr)
}
i++
}
FileNodes=FileNodes->next
}
xmlFree(FileNodes)
simulation.SIM_SPIRAL[i].flag=0
}
if((!xmlStrcmp(szAttr,(const xmlChar *)"axial")))
{
xmlNodePtr FileNodes=curNode->children
int i=0
while(FileNodes!=NULL)
{
if((!xmlStrcmp(FileNodes->name,(const xmlChar *)"FILE")))
{
szAttr = xmlGetProp(FileNodes,BAD_CAST "name")
if(szAttr!=NULL)
{
/* SIM_AXIAL[i].Name=(char*)szAttr*/
strcpy(simulation.SIM_AXIAL[i].Name,(char*)szAttr)
}
szAttr=xmlGetProp(FileNodes,BAD_CAST "sliceNum")
if(szAttr!=NULL)
{
simulation.SIM_AXIAL[i].Num=atoi((char*)szAttr)
}
i++
}
FileNodes=FileNodes->next
}
xmlFree(FileNodes)
simulation.SIM_AXIAL[i].flag=0
}
}
xmlFree(szAttr)
}
curNode = curNode->next
}
xmlFreeDoc(doc)
/*return 0*/
}
有什么不明白的再问吧!
简单步骤分步阅读1
/3
下载 WikiTaxi 和离线维基百科数据库
在你使用 WikiTaxi 之前,必须先下载它和维基百科的离线数据库,我们提供了简化版的英文版、完整英文版和中文版的维基数据库供大家下载,下载链接位于文章结尾处,请根据自己的需求选择下载。不过数据比较大,并且服务器位于国外,速度有点不尽人意,只能有点耐心吧。
2
/3
导入维基数据库到 WikiTaxi
因为维基百科提供的离线数据库(.xml.bz2)文件格式 WikiText 并不能直接使用,所以我们需要先将数据库转换成 WikiTaxi 的 .taxi 格式。下载解压 WikiTaxi 之后你可以看到一个 WikiTaxi_Importer.exe 的文件,双击运行它。简单来说,它就是一个转换数据库格式的工具。使用方法和简单,第一项选择 .xml.bz2 文件,第二项选择要保存转换好的.taxi文件,然后按 Import Now 即可开始。中间那个横条是用来调整分配多少内存给该工具来进行转换工作,当然能用的内存越多,转换速度也就也快了。转换好之后,如没特别需要,之前那个.xml.bz2的文件你可以删除掉了。
3
/3
运行 WikiTaxi
如果你已经制作好.taxi数据库之后,那么双击运行 wikitaxi.exe ,在菜单里选择 “Options”->“Open *.taxi Database”来打开刚才那个制作好的.taxi数据库文件即可。然后,就没然后了,你现在已经拥有一个离线的维基百科数据库了!想查询什么直接搜索就行了。
使用方法
1
/2
WikiTaxi首先需要Wikipedia的数据文件,比如在这里可以下载英文版本的备份导出文件:
http://dumps.wikimedia.org/enwiki/
一般选择pages-articles.xml.bz2,20100916的备份导出文件已经达到了6.1G。
下载之后,运行WikiTaxi_Importer.exe,将该数据文件转换提取成自己的数据库格式文件.taxi,通常设置更多的内存,会提高转换提取的速度,这个过程可能会有几十分钟以上。WikiTaxi转换提取后的数据库约为10.7G。
2
/2
转换提取完成后,运行WikiTaxi.exe, 打开数据库文件,即可开始离线浏览、搜索Wikipedia了,默认是随机挑选的页面。在数据库转换提取正确的情况下,就可以删除Wikipedia备份导出文件了。如果希望运行时自动加载数据库文件,可以创建使用命令行参数方式,
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)