Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用Boost';s属性树_C++_Xml_Boost_Boost Propertytree - Fatal编程技术网

C++ 使用Boost';s属性树

C++ 使用Boost';s属性树,c++,xml,boost,boost-propertytree,C++,Xml,Boost,Boost Propertytree,我一直在开发一个XML读写器,我使用Boost的属性树来实现这一点 一切正常,输出文件中只缺少一件事:我想在文件顶部添加两个头标记。现在,唯一的标题是这个,由Boost的write_xml()函数自动编写: <?xml version="1.0" encoding="UTF-8" standalone="no" ?> 但是,我想在已有的基础上添加以下两个: <!-- Custom stylesheet --> <?xml-stylesheet type="te

我一直在开发一个XML读写器,我使用Boost的属性树来实现这一点

一切正常,输出文件中只缺少一件事:我想在文件顶部添加两个头标记。现在,唯一的标题是这个,由Boost的
write_xml()
函数自动编写:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

但是,我想在已有的基础上添加以下两个:

<!-- Custom stylesheet -->
<?xml-stylesheet type="text/xsl" href="browser_view.xslt"?>
<!-- Authentic View -->
<?xmlspysps authentic_view.sps?>

有人知道在用Boost生成文件后,我如何不用编辑它就可以做到这一点吗?

这个词是“处理指令”。我很确定您不能(为什么他们要实现它?毕竟没有boostxml库)

在仔细检查
xml\u writer\u设置之后
实际上没有任何东西可以控制处理指令的打印(否则,您可能会抑制它们,而是自己打印整个序言)

以下是我对PugiXML的看法:

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <iostream>

#include <pugixml.hpp>

int main() {

    std::stringstream ss;

    {
        boost::property_tree::ptree pt;
        pt.add("demo", "bla");
        boost::property_tree::xml_parser::write_xml(ss, pt);
    }

    {
        pugi::xml_document doc;
        doc.load(ss);

        auto pi = doc.prepend_child(pugi::xml_node_type::node_pi);
        pi.set_name("xmlspysps");
        pi.set_value("authentic_view.sps");

        pi = doc.prepend_child(pugi::xml_node_type::node_pi);
        pi.set_name("xml-stylesheet");
        pi.set_value("type=\"text/xsl\" href=\"browser_view.xslt\"");

        doc.save_file("test.xml");
    }
}
#包括
#包括
#包括
#包括
int main(){
std::stringstream-ss;
{
boost::property_tree::ptree pt;
增加部分(“演示”、“bla”);
boost::property_tree::xml_parser::write_xml(ss,pt);
}
{
pugi::xml_文档文档;
文件加载(ss);
auto pi=doc.prepend\u child(pugi::xml\u node\u type::node\u pi);
pi.集合名称(“xmlspysps”);
pi.set_值(“authentic_view.sps”);
pi=doc.prepend\u child(pugi::xml\u node\u type::node\u pi);
pi.set_name(“xml样式表”);
pi.set_值(“type=\”text/xsl\”href=\“browser\u view.xslt\”);
doc.save_文件(“test.xml”);
}
}
保存:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="browser_view.xslt"?>
<?xmlspysps authentic_view.sps?>
<demo>bla</demo>

布拉

当然,如果你真的想序列化一个
ptree
,那效率会非常低,但显然你不仅仅是在序列化。您正在标记,为此您需要一个标记库,最好是一个支持XML的库。

这个词是“处理指令”。我很确定你不能(为什么他们要实现它?毕竟没有Boost Xml库)@sehe,有一个write_Xml()函数,为什么不可能呢?因为它不写Xml!它编写了一个属性树。(duh)(它碰巧是以XML的一个子集的格式编写的,但这并不意味着必须存在其他XML特性)它是以XML的方式编写属性树的。“我不明白你想证明什么,我很确定有办法做到我想要的,我只是在文档中找不到。实际上你是对的,@sehe。”。使用你的关键字,我发现一个线程说它无法完成,但提供了一个解决方案。感谢你的回答,但不幸的是,我无法使用任何外部库。