void parseQuery(const char* queryStr,const char* xmlFileName)
{
XQilla xqilla;//构造函数中初始化Xerces-C,析构函数中释放
//建立查询器
XQQuery* query = xqilla.parse(X(queryStr));
//获取环境
DynamicContext* context = query->createDynamicContext();
//加载文件到队列
Sequence seq = context->resolveDocument(X(xmlFileName));
if(!seq.isEmpty() && seq.first()->isNode())
{
context->setContextItem(seq.first());
context->setContextPosition(1);
context->setContextSize(1);
}
//执行查询
Result result = query->execute(context);
//输出结果
Item::Ptr item;
while(item = result->next(context)) {
std::cout << UTF8(item->asString(context)) << std::endl;
}
}
int main(int argc, char *argv[])
{
parseQuery("foo/bar/@baz","foo.xml");
return 0;
}
{
XQilla xqilla;//构造函数中初始化Xerces-C,析构函数中释放
//建立查询器
XQQuery* query = xqilla.parse(X(queryStr));
//获取环境
DynamicContext* context = query->createDynamicContext();
//加载文件到队列
Sequence seq = context->resolveDocument(X(xmlFileName));
if(!seq.isEmpty() && seq.first()->isNode())
{
context->setContextItem(seq.first());
context->setContextPosition(1);
context->setContextSize(1);
}
//执行查询
Result result = query->execute(context);
//输出结果
Item::Ptr item;
while(item = result->next(context)) {
std::cout << UTF8(item->asString(context)) << std::endl;
}
}
int main(int argc, char *argv[])
{
parseQuery("foo/bar/@baz","foo.xml");
return 0;
}
2021年目标:完成新书《闻缺陷则喜》,本博客右上公告有下载、阅读链接。