添加xml样式表处理指令以增强property_tree [英] Add xml-stylesheet processing instructions to boost property_tree

查看:135
本文介绍了添加xml样式表处理指令以增强property_tree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用boost / property_tree来创建一个XML文件。
很遗憾,我无法弄清楚如何向文件中添加xml样式表处理指令。

I am using boost/property_tree to create an XML file. Unfortunately I cannot figure out how to add xml-stylesheet processing instructions to the file.

希望的输出:

<?xml version="1.0" encoding="utf-8"?> <-- This is added automatically
<?xml-stylesheet type="text/xsl" href="report.xsl"?> <-- How to add this line
<report>
...
</report>

是否可以使用boost / property_tree / ptree?

Is that possible with boost/property_tree/ptree?

推荐答案

看来boost / property_tree xml writer不支持xml样式表处理指令。第一行(xml版本)只是硬编码在write_xml_internal函数中。

It appears that boost/property_tree xml writer doesn't have a support for xml stylesheets processing instructions. First line (xml version) is simply hardcoded in the write_xml_internal function.

所以我刚刚写了自己写的xml函数, xml样式表。

So I've just written my own write xml function, which is doing exactly the same, plus adds xml stylesheet.

void WriteXML(std::ostream &output, ptree &root)
{
 boost::property_tree::xml_writer_settings<char> settings('\t', 1);

 output << "<?xml version=\"1.0\" encoding=\"";
 output << settings.encoding;
 output << "\"?>\n";
 output << "<?xml-stylesheet type=\"text/xsl\" href=\"report.xsl\"?>\n";

 write_xml_element(output, std::basic_string<ptree::key_type::value_type>(), root, -1, settings);
}

这篇关于添加xml样式表处理指令以增强property_tree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆