C++ 使用pugixml解析XML
我正在尝试使用web服务获取internet时间,它为我提供了一个xml。现在,我尝试使用pugixml解析xml文件。XML返回C++ 使用pugixml解析XML,c++,xml,pugixml,C++,Xml,Pugixml,我正在尝试使用web服务获取internet时间,它为我提供了一个xml。现在,我尝试使用pugixml解析xml文件。XML返回 <?xml version="1.0" encoding="ISO-8859-1" ?> <timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.
<?xml version="1.0" encoding="ISO-8859-1" ?>
<timezone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.earthtools.org/timezone.xsd">
<version>1.0</version>
<location>
<latitude>22.5667</latitude>
<longitude>88.3667</longitude>
</location>
<offset>5.5</offset>
<suffix>E*</suffix>
<localtime>20 Jul 2014 14:48:10</localtime>
<isotime>2014-07-20 14:48:10 +0530</isotime>
<utctime>2014-07-20 09:18:10</utctime>
<dst>Unknown</dst>
</timezone>
1
22.5667
88.3667
5.5
E*
2014年7月20日14:48:10
2014-07-20 14:48:10 +0530
2014-07-20 09:18:10
不为人知
我试图解析它的方式
pugi::xml_document doc;
if (!doc.load_file("time.xml")) return -1;
pugi::xml_node tools = doc.child("timezone").child("localtime");
//[code_traverse_iter
for (pugi::xml_node_iterator it = tools.begin(); it != tools.end(); ++it)
{
std::cout << "Tool:";
for (pugi::xml_attribute_iterator ait = it->attributes_begin(); ait != it->attributes_end(); ++ait)
{
std::cout << " " << ait->name() << "=" << ait->value();
}
std::cout << std::endl;
}
return 0;
pugi::xml\u文档文档;
如果(!doc.load_file(“time.xml”))返回-1;
pugi::xml_node tools=doc.child(“时区”).child(“本地时间”);
//[代码]
for(pugi::xml_node_iterator it=tools.begin();it!=tools.end();+it)
{
std::cout attributes_begin();ait!=it->attributes_end();++ait)
{
标准::cout
或
或
<localtime>20 Jul 2014 14:48:10</localtime>
const char* localtime = doc.child("timezone").child("localtime").text().get();
const char* localtime = doc.child("timezone").child_value("localtime");