Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
264 views
in Technique[技术] by (71.8m points)

c++ - Add xml-stylesheet processing instructions to boost property_tree

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.

Desirable output:

<?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>

Is that possible with boost/property_tree/ptree?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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('', 1);

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...