tinyxml2 的 TiXmlAttribute 等价物是什么以及如何使用它?
What is the equivalent of TiXmlAttribute for tinyxml2 and how to use it?
我遇到了无法使用 tinyxml2 解决的问题。
我有一个接收参数 a XMLElement
的函数,我需要迭代它的属性。使用 tinyxml,这有效:
void xmlreadLight(TiXmlElement* light){
for (TiXmlAttribute* a = light->FirstAttribute(); a ; a = a->Next()) {
//Do stuff
}
}
使用与 tinyxml2 相同的方法,如下例所示,我收到以下错误:
a value of type const tinyxml2::XMLAttribute *
cannot be used to initialize an entity of type tinyxml2::XMLAttribute *
void xmlreadLight(XMLElement* light){
for (XMLAttribute* a = light->FirstAttribute(); a ; a = a->Next()) {
//Do stuff
}
}
有问题的 XML 代码是:
<lights>
<light type="POINT" posX=-1.0 posY=1.0 posZ=-1.0 ambtR=1.0 ambtG=1.0 ambtB=1.0 />
</lights>
其中光是 XMLElement
传递给函数 xmlreadLight
的。不确定我的问题是否设置正确,所以如果缺少某些信息,请告诉我。
根据错误消息,您似乎需要执行以下操作:
for (const XMLAttribute* a = light->FirstAttribute(); a ; a = a->Next()) { ...
^^^^^
据推测,FirstAttribute
的return类型已经在tinyxml2中做了const
。
如果您检查 Github 存储库中第 1513 行的 tinyxml2.h
文件,您将看到:
/// Return the first attribute in the list.
const XMLAttribute* FirstAttribute() const {
return _rootAttribute;
}
我遇到了无法使用 tinyxml2 解决的问题。
我有一个接收参数 a XMLElement
的函数,我需要迭代它的属性。使用 tinyxml,这有效:
void xmlreadLight(TiXmlElement* light){
for (TiXmlAttribute* a = light->FirstAttribute(); a ; a = a->Next()) {
//Do stuff
}
}
使用与 tinyxml2 相同的方法,如下例所示,我收到以下错误:
a value of type
const tinyxml2::XMLAttribute *
cannot be used to initialize an entity of typetinyxml2::XMLAttribute *
void xmlreadLight(XMLElement* light){
for (XMLAttribute* a = light->FirstAttribute(); a ; a = a->Next()) {
//Do stuff
}
}
有问题的 XML 代码是:
<lights>
<light type="POINT" posX=-1.0 posY=1.0 posZ=-1.0 ambtR=1.0 ambtG=1.0 ambtB=1.0 />
</lights>
其中光是 XMLElement
传递给函数 xmlreadLight
的。不确定我的问题是否设置正确,所以如果缺少某些信息,请告诉我。
根据错误消息,您似乎需要执行以下操作:
for (const XMLAttribute* a = light->FirstAttribute(); a ; a = a->Next()) { ...
^^^^^
据推测,FirstAttribute
的return类型已经在tinyxml2中做了const
。
如果您检查 Github 存储库中第 1513 行的 tinyxml2.h
文件,您将看到:
/// Return the first attribute in the list.
const XMLAttribute* FirstAttribute() const {
return _rootAttribute;
}