-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
73 lines (71 loc) · 2.19 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "src/parser.hpp"
#include "src/xpath.hpp"
extern int CXML_PARSER_STATUS; //解析状态
extern int XPATH_PARSE_STATUE;
int main()
{
using std::cout;
using std::endl;
clock_t start, end;
start = clock();
CXMLNode *root = parse_from_string("\
<bookstore company=\"codecat\" boss=\"man\">\n\
<book category=\"CHILDREN\">\n\
<title>Harry Potter</title>\n\
<author>J K.Rowlingk</author>\n\
<year>2005</year><br>\n\
<price>29.99 </price>\n\
</book>\n\
<book category=\"WEB\">\n\
<title>Learning XML</title>\n\
<author>Erik T.Ray</author>\n\
<year>2003 </year>\n\
<price>39.95 </price>\n\
</book>\n\
</bookstore>");
//cout << root->children.size() << endl;
if (CXML_PARSER_STATUS == CXML_SYNTAX_ERROR)
{
std::puts(">xml解析异常");
return 0;
}
else
{
std::puts(">xml解析成功");
}
const CXMLNode_result *result1 = xpath("/bookstore/book[@category=CHILDREN]//text()", root);
const CXMLNode_result *result2 = xpath("/bookstore/book/title/../price/text()", root);
if (XPATH_PARSE_STATUE == XPATH_SYNTAX_ERROR)
{
std::puts(">xpath解析异常");
return 0;
}
else
{
std::puts(">xpath解析成功");
}
cout << "测试样例1:" << result1->text << endl;
cout << "测试样例2:" << result2->text << endl;
end = clock();
cout << "\n函数运行花费:" << (double)(end - start) / CLOCKS_PER_SEC << "秒";
// CXMLNode *result = search("book", root);
// cout << result->children.size() << endl;
// using std::puts;
// puts("解析到的属性:");
// if (result->attr != nullptr)
// {
// for (auto m : result->attr->attributes)
// {
// //属性
// cout << "key:" << m.first << " value:" << m.second << endl;
// }
// }
// //
// puts("解析子节点 及节点值");
// for (auto m : result->children)
// {
// //节点名称
// cout << m->name << ":" << m->text->content << endl;
// }
return 0;
}