Tinyxml 设置属性
我不知道我做错了什么。我正在用 C++ 编写一个简单的程序来使用 TinyXml 编辑 xml 配置文件。
这是我的配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<video>
<fps state="notlimited">
<limit value="60" />
</fps>
</video>
</config>
这是编辑文件的代码部分:
if ( limitFPS )
{
cout << "Enter the FPS limit:" << endl;
cin >> fpsLimit;
TiXmlElement *fpsState = hConfig.FirstChildElement( "config" ).FirstChildElement( "video" ).FirstChildElement( "fps" ).ToElement();
fpsState->SetAttribute("state", "limited");
TiXmlElement *fpsLimitElement = hConfig.FirstChildElement( "config" ).FirstChildElement( "video" ).FirstChildElement( "fps" ).FirstChildElement( "limit" ).ToElement();
fpsLimitElement->SetAttribute( "value", fpsLimit );
}
如果用户表示他们想要限制 fps,则标签 fps 的属性“状态”将更改为受限。然后将限制的属性“值”设置为用户指定的 fps 级别。
但是,当我运行该程序时,它不会更改指定的属性。我检查了我的代码,没有发现其中有任何错误。我也没有收到任何错误。
那么我做错了什么?
I have not idea what I am doing wrong. I am writing a simple program in C++ to edit a xml config file using TinyXml.
Here is my config file:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<video>
<fps state="notlimited">
<limit value="60" />
</fps>
</video>
</config>
Here is the section of code that edits the file:
if ( limitFPS )
{
cout << "Enter the FPS limit:" << endl;
cin >> fpsLimit;
TiXmlElement *fpsState = hConfig.FirstChildElement( "config" ).FirstChildElement( "video" ).FirstChildElement( "fps" ).ToElement();
fpsState->SetAttribute("state", "limited");
TiXmlElement *fpsLimitElement = hConfig.FirstChildElement( "config" ).FirstChildElement( "video" ).FirstChildElement( "fps" ).FirstChildElement( "limit" ).ToElement();
fpsLimitElement->SetAttribute( "value", fpsLimit );
}
If the user has said that they want to limit the fps then the attribute "state" for tag fps is change to limited. Then the attribute "value" for the limit is set to the fps level the user has specified.
However when I run the program it dose not change the specified attributes. I have looked over my code and can not find any errors in it. Also I am not getting any errors.
So what am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.SaveFile() 保存对 xml 文档的更改
.SaveFile() saves changes to the xml document