如何使用 libxml++ 解析 XML 字符串而不是 XML 文件
How to parse XML string instead of XML file with libxml++
我正在尝试解析C++程序中包含XML文档的字符串。我知道我可以使用 libxml2 用 C 做到这一点,但我想要一个使用 libxml++ 的C++解决方案(它建立在 libxml2 之上(。
目前,我可以从这样的文件中解析:
DomParser *parser = new DomParser;
parser->parse_file("sample.xml");
答案很简单(几乎与解析文件相同(。
parser->parse_memory(xml_document);
就我而言,我需要支持两者的选项,所以这就是我想出的解决方案。
ifstream input_stream;
input_stream.open(xml.c_str(), ios::in); // attempt to open the file for reading
if(input_stream.fail())
{
parser->parse_memory(xml); // is not a file, parse as a string
}
else
{
parser->parse_file(xml); // is a file, parse as a file
}
相关文章:
- C++RapidXml-使用first_node()遍历以修改XML文件中节点的值
- c++ 读取 xml 文件的内容
- 删除 XML 文件中的子节点C++
- 在Cmake构建CmakeList.txt中读取/解析XML文件
- 使用 libxml2 解析 XML 文件时缺少元素值
- 为什么TinyXML2的XMLDocument::FirstChild()函数在尝试解析这个有效的XML文件时返回NULL?
- 如何循环 n 次,在 xml 文件中每个循环一个级别
- 无法从 XML 文件中获取值
- 如何让用户在 tinyxml2 中输入 XML 文件的路径
- 使用 TinyXML2 读取 C++ 中的 XML 文件
- OPENCV - 如何在OpenCV中使用Haar Cascade Github xml文件?
- 我们如何重新制作程序以打开xml文件并在价格单词之后读取百分比值并更改此值
- 如何使用QXmlStreamReader解析包含对其他XML文件的引用的XML文件
- 如何解析列存储格式的XML文件
- OpenCV - 打开一个从C++到Python的XML文件
- 修改 XML 文件 QXMLStreamReader/Writer
- 如何使用libcurl c ++从url保存XML文件
- C++/RapidXML:编辑节点并写入新的 XML 文件没有更新的节点
- 如何使用所有其他文件信息来编译代码,例如HAAR级联训练的权重的XML文件
- 是否可以将信息从XML文件转换为CPP