"Boost xml"의 두 판 사이의 차이
jjuiddong
(한 사용자의 중간의 편집 4개 숨겨짐) | |||
2번째 줄: | 2번째 줄: | ||
** http://www.technical-recipes.com/2014/using-boostproperty_tree/ | ** http://www.technical-recipes.com/2014/using-boostproperty_tree/ | ||
** 이보다 더 좋은 예제는 없을 듯. | ** 이보다 더 좋은 예제는 없을 듯. | ||
+ | |||
+ | === XML Example (hardware_settings_config.xml) === | ||
+ | <?xml version="1.0" encoding="UTF-8" ?> | ||
+ | <hardware_settings_config version="56" deviceId="0x1380"> | ||
+ | <cpu> | ||
+ | <threadStrategy parallelUpdateRender="true" workerMapFile="system/workerMap8Core.xml" forceFeedbackProcessor="6" dvdStorageProcessor="7" dataSetMonitorProcessor="4" renderProcessor="0" updateProcessor="2" fileStreamProcessor="5" /> | ||
+ | </cpu> | ||
+ | </hardware_settings_config> | ||
=== XML Read Example === | === XML Read Example === | ||
34번째 줄: | 42번째 줄: | ||
=== XML Write Example === | === XML Write Example === | ||
+ | |||
+ | #include <iostream> | ||
+ | #include <string> | ||
+ | #include <boost/property_tree/ptree.hpp> | ||
+ | #include <boost/property_tree/xml_parser.hpp> | ||
+ | using namespace std; | ||
+ | void main() | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | // boost property tree | ||
+ | using boost::property_tree::ptree; | ||
+ | ptree props; | ||
+ | |||
+ | props.put<bool>("hardware_settings_config.cpu.threadStrategy.<xmlattr>.parallelUpdateRender", false); | ||
+ | boost::property_tree::write_xml("wr.xml", props); | ||
+ | } | ||
+ | catch (std::exception&e) | ||
+ | { | ||
+ | cout << "Write Error " << e.what() << endl; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | * xml writing 시 탭을 이용해서 예쁘게 출력하려면 다음 페이지를 참조하자. | ||
+ | ** http://stackoverflow.com/questions/6572550/boostproperty-tree-xml-pretty-printing | ||
+ | |||
+ | boost::property_tree::xml_writer_settings<string> settings('\t', 1); | ||
+ | boost::property_tree::write_xml(fileName, props, std::locale(), settings); |
2015년 8월 24일 (월) 15:08 기준 최신판
- 참고자료
- http://www.technical-recipes.com/2014/using-boostproperty_tree/
- 이보다 더 좋은 예제는 없을 듯.
[편집] XML Example (hardware_settings_config.xml)
<?xml version="1.0" encoding="UTF-8" ?> <hardware_settings_config version="56" deviceId="0x1380"> <cpu> <threadStrategy parallelUpdateRender="true" workerMapFile="system/workerMap8Core.xml" forceFeedbackProcessor="6" dvdStorageProcessor="7" dataSetMonitorProcessor="4" renderProcessor="0" updateProcessor="2" fileStreamProcessor="5" /> </cpu> </hardware_settings_config>
[편집] XML Read Example
#include <iostream> #include <string> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> using namespace std; void main() { string fileName = "hardware_settings_config.xml"; try { // boost property tree using boost::property_tree::ptree; using std::string; ptree props; boost::property_tree::read_xml(fileName, props); bool parallelUpdateRender = props.get<bool>("hardware_settings_config.cpu.threadStrategy.<xmlattr>.parallelUpdateRender", false); cout << "parallelUpdateRender = " << parallelUpdateRender << endl; string workerMapFile = props.get<string>("hardware_settings_config.cpu.threadStrategy.<xmlattr>.workerMapFile", ""); cout << "workerMapFile = " << workerMapFile << endl; } catch (std::exception&e) { cout << "Error " << e.what() << endl; } }
[편집] XML Write Example
#include <iostream> #include <string> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/xml_parser.hpp> using namespace std; void main() { try { // boost property tree using boost::property_tree::ptree; ptree props; props.put<bool>("hardware_settings_config.cpu.threadStrategy.<xmlattr>.parallelUpdateRender", false); boost::property_tree::write_xml("wr.xml", props); } catch (std::exception&e) { cout << "Write Error " << e.what() << endl; } }
- xml writing 시 탭을 이용해서 예쁘게 출력하려면 다음 페이지를 참조하자.
boost::property_tree::xml_writer_settings<string> settings('\t', 1); boost::property_tree::write_xml(fileName, props, std::locale(), settings);