C++ 提取xml字符串中的(不调用xml相关库)
发布时间
阅读量:
阅读量
函数说明 :本函数接收一个符合xml格式的字符串及待查找的节点名称作为输入参数,其功能是提取与该节点相对应的内容信息。若目标节点不存在或输入字符串格式不合法,则返回一个空字符串作为输出结果。
示例:
输入:
inxml = "<people><name>wwh</name></people>";
path = "people.name";
输出:
"wwh"
完整代码实现:
string GetXMLValue(string inxml, string path) {
unordered_map<string, string> hash_m;
stack<string> st;
size_t ptr = 0;
string temp = "";
while (ptr < inxml.size()) {
if (inxml[ptr] == '<') {
string node = "";
while (inxml[++ptr] != '>') {
node += inx
全部评论 (0)
还没有任何评论哟~
