<tfoot id='urXwn'></tfoot>

    <legend id='urXwn'><style id='urXwn'><dir id='urXwn'><q id='urXwn'></q></dir></style></legend>

    1. <i id='urXwn'><tr id='urXwn'><dt id='urXwn'><q id='urXwn'><span id='urXwn'><b id='urXwn'><form id='urXwn'><ins id='urXwn'></ins><ul id='urXwn'></ul><sub id='urXwn'></sub></form><legend id='urXwn'></legend><bdo id='urXwn'><pre id='urXwn'><center id='urXwn'></center></pre></bdo></b><th id='urXwn'></th></span></q></dt></tr></i><div id='urXwn'><tfoot id='urXwn'></tfoot><dl id='urXwn'><fieldset id='urXwn'></fieldset></dl></div>
      • <bdo id='urXwn'></bdo><ul id='urXwn'></ul>

      1. <small id='urXwn'></small><noframes id='urXwn'>

        boost::property_tree XML 漂亮打印

        时间:2023-07-20

        <small id='Tr72G'></small><noframes id='Tr72G'>

        • <tfoot id='Tr72G'></tfoot>

              <tbody id='Tr72G'></tbody>

            <i id='Tr72G'><tr id='Tr72G'><dt id='Tr72G'><q id='Tr72G'><span id='Tr72G'><b id='Tr72G'><form id='Tr72G'><ins id='Tr72G'></ins><ul id='Tr72G'></ul><sub id='Tr72G'></sub></form><legend id='Tr72G'></legend><bdo id='Tr72G'><pre id='Tr72G'><center id='Tr72G'></center></pre></bdo></b><th id='Tr72G'></th></span></q></dt></tr></i><div id='Tr72G'><tfoot id='Tr72G'></tfoot><dl id='Tr72G'><fieldset id='Tr72G'></fieldset></dl></div>
            • <bdo id='Tr72G'></bdo><ul id='Tr72G'></ul>
                • <legend id='Tr72G'><style id='Tr72G'><dir id='Tr72G'><q id='Tr72G'></q></dir></style></legend>

                • 本文介绍了boost::property_tree XML 漂亮打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 boost::property_tree 在我的应用程序中读取和写入 XML 配置文件.但是当我编写文件时,输出看起来有点难看,文件中有很多空行.问题是它也应该由人类编辑,所以我想获得更好的输出.

                  I'm using boost::property_tree to read and write XML configuration files in my application. But when I write the file the output looks kind of ugly with lots of empty lines in the file. The problem is that it's supposed to be edited by humans too so I'd like to get a better output.

                  举个例子,我写了一个小测试程序:

                  As an example I wrote a small test program :

                  #include <boost/property_tree/ptree.hpp>
                  #include <boost/property_tree/xml_parser.hpp>
                  
                  int main( void )
                  {
                      using boost::property_tree::ptree;
                      ptree pt;
                  
                      // reading file.xml
                      read_xml("file.xml", pt);
                  
                      // writing the unchanged ptree in file2.xml
                      boost::property_tree::xml_writer_settings<char> settings('	', 1);
                      write_xml("file2.xml", pt, std::locale(), settings);
                  
                      return 0;
                  }
                  

                  file.xml 包含:

                  file.xml contains:

                  <?xml version="1.0" ?>
                  <config>
                      <net>
                          <listenPort>10420</listenPort>
                      </net>
                  </config>
                  

                  运行后的程序file2.xml包含:

                  after running the program file2.xml contains:

                  <?xml version="1.0" encoding="utf-8"?>
                  <config>
                  
                  
                  
                      <net>
                  
                  
                  
                          <listenPort>10420</listenPort>
                      </net>
                  </config>
                  

                  除了手动查看输出并删除空行之外,还有什么方法可以获得更好的输出?

                  Is there a way to have a better output, other than going manually through the output and deleting empty lines?

                  推荐答案

                  解决方案是在对 read_xml 的调用中添加 trim_whitespace 标志:

                  The solution was to add the trim_whitespace flag to the call to read_xml:

                  #include <boost/property_tree/ptree.hpp>
                  #include <boost/property_tree/xml_parser.hpp>
                  
                  int main( void )
                  {
                      // Create an empty property tree object
                      using boost::property_tree::ptree;
                      ptree pt;
                  
                      // reading file.xml
                      read_xml("file.xml", pt, boost::property_tree::xml_parser::trim_whitespace );
                  
                      // writing the unchanged ptree in file2.xml
                      boost::property_tree::xml_writer_settings<char> settings('	', 1);
                      write_xml("file2.xml", pt, std::locale(), settings);
                  
                      return 0;
                  }
                  

                  该标志记录在此处 但该库的当前维护者 (Sebastien Redl) 很友好地回答并指出了它.

                  The flag is documented here but the current maintainer of the library (Sebastien Redl) was kind enough to answer and point me to it.

                  这篇关于boost::property_tree XML 漂亮打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:unique_ptr 提升等效吗? 下一篇:是 boost shared_ptr &lt;XXX&gt;线程安全?

                  相关文章

                    <bdo id='0gPei'></bdo><ul id='0gPei'></ul>
                      <i id='0gPei'><tr id='0gPei'><dt id='0gPei'><q id='0gPei'><span id='0gPei'><b id='0gPei'><form id='0gPei'><ins id='0gPei'></ins><ul id='0gPei'></ul><sub id='0gPei'></sub></form><legend id='0gPei'></legend><bdo id='0gPei'><pre id='0gPei'><center id='0gPei'></center></pre></bdo></b><th id='0gPei'></th></span></q></dt></tr></i><div id='0gPei'><tfoot id='0gPei'></tfoot><dl id='0gPei'><fieldset id='0gPei'></fieldset></dl></div>
                      <tfoot id='0gPei'></tfoot>
                    1. <small id='0gPei'></small><noframes id='0gPei'>

                    2. <legend id='0gPei'><style id='0gPei'><dir id='0gPei'><q id='0gPei'></q></dir></style></legend>