在C ++中处理XML属性时,应根据给定的属性使用什么来运行不同的操作?
目前,我有这样的事情:
// get list of attributes for an XML element into member called 'attributes'
// ...
// run appropriate functions for each attribute
for (auto attribute : attributes)
{
auto name = attribute.name;
auto value = attribute.value;
if (name == "x")
doSomethingWithX(value);
else if (name == "y")
doSomethingWithY(value);
}
Run Code Online (Sandbox Code Playgroud)
对于仅几个属性名称来说,这还不错-但是如果使用较大的属性名称(> 15),则看起来会变得凌乱,而且我担心性能问题。
有没有更好的方法来处理这样的属性?