gpt4 book ai didi

c++ - 使 Xerces 解析字符串而不是文件

转载 作者:IT老高 更新时间:2023-10-28 22:17:40 27 4
gpt4 key购买 nike

我知道如何仅使用 XercesDOMParser 从 xml 文件创建完整的 dom:

xercesc::XercesDOMParser parser = new xercesc::XercesDOMParser();
parser->parse(path_to_my_file);
parser->getDocument(); // From here on I can access all nodes and do whatever i want

嗯,这行得通...但是如果我想解析一个字符串怎么办?类似的东西

std::string myxml = "<root>...</root>";
xercesc::XercesDOMParser parser = new xercesc::XercesDOMParser();
parser->parse(myxml);
parser->getDocument(); // From here on I can access all nodes and do whatever i want

我正在使用版本 3。查看 AbstractDOMParser 内部,我看到了 parse 方法及其重载版本,仅解析文件。

如何从字符串中解析?

最佳答案

创建一个 MemBufInputSourceparse那:

xercesc::MemBufInputSource myxml_buf(myxml.c_str(), myxml.size(),
"myxml (in memory)");
parser->parse(myxml_buf);

关于c++ - 使 Xerces 解析字符串而不是文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4691039/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com