Answer the question
In order to leave comments, you need to log in
How to modify xml file?
Good afternoon friends! How to modify xml file?
I have an XML file data.xml with the following content:
<?xml version="1.0" encoding="utf-8"?>
<Controls PageSize_Width="70">
<PictureBox index="1" hashName="d6deadf9-d41a-4583-9d9b-95fae10baca0" Width="12,319" Height="12,319" Roate="0" />
<PictureBox index="2" hashName="90df0e11-9dc3-4439-bb54-3e5a16da41a2" Width="12,319" Height="12,319" Roate="0"/>
</Controls>
#include <iostream>
#include <string>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/foreach.hpp>
#include <boost/range/iterator_range.hpp>
//путь к файлу
const std::string PRT_PATT_XML = "./data.xml";
const std::string MODIFE = "./modified.xml";
int main() {
using boost::property_tree::ptree;
ptree pt1;
read_xml(PRT_PATT_XML, pt1);
BOOST_FOREACH( const ptree::value_type & childTree, pt1.get_child("Controls") ) {
std::string subtreeCaption = childTree.first;
ptree sub_pt = childTree.second;
if (subtreeCaption == "PictureBox") {
for(ptree::value_type &v : sub_pt.get_child("<xmlattr>")) {
std::cout << "\t" << v.first << " = " << v.second.data() << std::endl;
if(v.first == "hashName") {
v.second.put<std::string>((v.first), "ukrop");
}
}
}
}
write_xml(MODIFE, pt1);
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question