I read.These are my write functions.I can change value but not in xml file.I cant write new value to xml file.Will I change all file?
bool Data::WriteParameter(Parameter *parameter, std::vector<unsigned int> Indexes)
{
QFile programFile
(PARAMETER_FILE
);
//xml verildi XML_File xmlData;//bu file bu sinif içinde açılacak
bool result=false;
xmlData.read(&programFile);
element=xmlData.domDocument.documentElement();
if(element.tagName()=="Parameters" && element.hasChildNodes()==true)
{
element=element.firstChildElement();
do
{
if(element.tagName().toStdString()==parameter->getName())
{
ChangeParameter(parameter,element,Indexes);
result=true;
break;
}
else
{
element=element.nextSiblingElement();
}
}while(!element.isNull());
xmlData.write(&programFile);
}
return result;
}
void Data
::ChangeParameter(Parameter
*parameter,
QDomElement element,std
::vector<unsigned int> Indexes
) {
unsigned int index;
parameterList=element.childNodes();
vector<unsigned int>::iterator itr;
for(itr=Indexes.begin();itr!=Indexes.end();itr++)
{
elementList=parameterList.item(*itr).toElement().childNodes();
for(index=0;index<(unsigned int)elementList.size();index++)
{
_element=elementList.item(index).toElement();
tagName=_element.tagName();
if(tagName=="Value")
{
elementText=_element.childNodes().item(0).toText();
dataLn=elementText.toCharacterData();
//elementText.setNodeValue(QString::number(parameter->Parameters[*itr]->getValue()));
dataLn.
replaceData(0,
QString::number(parameter
->Parameters
[*itr
]->getValue
()).
length(),
QString::number(parameter
->Parameters
[*itr
]->getValue
()));
}
}
}
}
{
const int IndentSize = 4;
domDocument.save(out, IndentSize);
return true;
}
bool Data::WriteParameter(Parameter *parameter, std::vector<unsigned int> Indexes)
{
QFile programFile(PARAMETER_FILE);//xml verildi
QDomElement element;//xml üzerinde işlem yapacak
XML_File xmlData;//bu file bu sinif içinde açılacak
bool result=false;
xmlData.read(&programFile);
element=xmlData.domDocument.documentElement();
if(element.tagName()=="Parameters" && element.hasChildNodes()==true)
{
element=element.firstChildElement();
do
{
if(element.tagName().toStdString()==parameter->getName())
{
ChangeParameter(parameter,element,Indexes);
result=true;
break;
}
else
{
element=element.nextSiblingElement();
}
}while(!element.isNull());
xmlData.write(&programFile);
}
return result;
}
void Data::ChangeParameter(Parameter *parameter, QDomElement element,std::vector<unsigned int> Indexes)
{
unsigned int index;
QString tagName;
QDomElement _element;QDomCharacterData dataLn;
QDomText elementText;
QDomNodeList parameterList,elementList;
parameterList=element.childNodes();
vector<unsigned int>::iterator itr;
for(itr=Indexes.begin();itr!=Indexes.end();itr++)
{
elementList=parameterList.item(*itr).toElement().childNodes();
for(index=0;index<(unsigned int)elementList.size();index++)
{
_element=elementList.item(index).toElement();
tagName=_element.tagName();
if(tagName=="Value")
{
elementText=_element.childNodes().item(0).toText();
dataLn=elementText.toCharacterData();
//elementText.setNodeValue(QString::number(parameter->Parameters[*itr]->getValue()));
dataLn.replaceData(0,QString::number(parameter->Parameters[*itr]->getValue()).length(),
QString::number(parameter->Parameters[*itr]->getValue()));
}
}
}
}
bool XML_File::write(QIODevice *device)
{
const int IndentSize = 4;
QTextStream out(device);
domDocument.save(out, IndentSize);
return true;
}
To copy to clipboard, switch view to plain text mode
Bookmarks