一,读取整个xml。
#include <iostream>
#include <xqilla/xqilla-simple.hpp>
#include <xqilla/runtime/Sequence.hpp>
//...
int main(int argc, char *argv[])
{
XQilla xqilla;//构造函数中初始化Xerces-C,析构函数中释放
//获取环境
DynamicContext* context = XQilla::createContext();
//加载文件到队列
Sequence seq = context->resolveDocument(X("foo.xml"));
//获取整个第一个结点(整个xml文件),并转化成const char*
const Item::Ptr ptr = seq.first();
const XMLCh* xmlp= ptr->asString(context);
UTF8Str utf8str(xmlp);
const char* p = utf8str.str();
return 0;
}
二,如果foo.xml不存在,报错。
void readXml() try
{
//获取环境
DynamicContext* context = XQilla::createContext();
//加载文件到队列
Sequence seq = context->resolveDocument(X("foo.xml"));
//获取整个第一个结点(整个xml文件),并转化成const char*
const Item::Ptr ptr = seq.first();
const XMLCh* xmlp= ptr->asString(context);
UTF8Str utf8str(xmlp);
const char* p = utf8str.str();
}
catch(XQException& e)
{
std::cout << "错误源文件" << e.getCppFile() << std::endl << "错误行数" << e.getCppLine() << std::endl ;
std::cout << "错误原因" << UTF8Str(e.getError()).str() << std::endl ;
}
int main(int argc, char *argv[])
{
XQilla xqilla;//构造函数中初始化Xerces-C,析构函数中释放
readXml();
}
#include <iostream>
#include <xqilla/xqilla-simple.hpp>
#include <xqilla/runtime/Sequence.hpp>
//...
int main(int argc, char *argv[])
{
XQilla xqilla;//构造函数中初始化Xerces-C,析构函数中释放
//获取环境
DynamicContext* context = XQilla::createContext();
//加载文件到队列
Sequence seq = context->resolveDocument(X("foo.xml"));
//获取整个第一个结点(整个xml文件),并转化成const char*
const Item::Ptr ptr = seq.first();
const XMLCh* xmlp= ptr->asString(context);
UTF8Str utf8str(xmlp);
const char* p = utf8str.str();
return 0;
}
二,如果foo.xml不存在,报错。
void readXml() try
{
//获取环境
DynamicContext* context = XQilla::createContext();
//加载文件到队列
Sequence seq = context->resolveDocument(X("foo.xml"));
//获取整个第一个结点(整个xml文件),并转化成const char*
const Item::Ptr ptr = seq.first();
const XMLCh* xmlp= ptr->asString(context);
UTF8Str utf8str(xmlp);
const char* p = utf8str.str();
}
catch(XQException& e)
{
std::cout << "错误源文件" << e.getCppFile() << std::endl << "错误行数" << e.getCppLine() << std::endl ;
std::cout << "错误原因" << UTF8Str(e.getError()).str() << std::endl ;
}
int main(int argc, char *argv[])
{
XQilla xqilla;//构造函数中初始化Xerces-C,析构函数中释放
readXml();
}
2021年目标:完成新书《闻缺陷则喜》,本博客右上公告有下载、阅读链接。