【发布时间】:2014-01-09 00:09:43
【问题描述】:
我想做这样的事情:
stringBuilder.AppendLine(" globalVar." + reader.GetAttribute(i).Name + " = " + reader[i] + "; //add param ");
其中“reader.GetAttribute(i).Name”是不起作用的组件。是否有等效的方法来获取属性的名称?
【问题讨论】:
我想做这样的事情:
stringBuilder.AppendLine(" globalVar." + reader.GetAttribute(i).Name + " = " + reader[i] + "; //add param ");
其中“reader.GetAttribute(i).Name”是不起作用的组件。是否有等效的方法来获取属性的名称?
【问题讨论】:
使用reader.MoveToAttribute(i),则可以使用reader.Name和reader.Value。
【讨论】:
直接在阅读器上使用Name 和Value - 请参阅下面Reading Attributes 的示例:
if (reader.HasAttributes) {
Console.WriteLine("Attributes of <" + reader.Name + ">");
while (reader.MoveToNextAttribute()) {
Console.WriteLine(" {0}={1}", reader.Name, reader.Value);
}
// Move the reader back to the element node.
reader.MoveToElement();
}
【讨论】:
GetAttribute() 返回属性的字符串值。它没有“名称”属性。尝试移动到属性,然后获取“名称”属性。
【讨论】: