【问题标题】:xmlreader, get the attribute's namexmlreader,获取属性名
【发布时间】:2014-01-09 00:09:43
【问题描述】:

我想做这样的事情:

stringBuilder.AppendLine("   globalVar." + reader.GetAttribute(i).Name + " = " + reader[i] + "; //add param ");

其中“reader.GetAttribute(i).Name”是不起作用的组件。是否有等效的方法来获取属性的名称?

【问题讨论】:

标签: c# xml xmlreader


【解决方案1】:

使用reader.MoveToAttribute(i),则可以使用reader.Namereader.Value

【讨论】:

  • 感谢这最终奏效了……我不得不改变一些逻辑,但它确实奏效了。
【解决方案2】:

直接在阅读器上使用NameValue - 请参阅下面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();
}

【讨论】:

    【解决方案3】:

    GetAttribute() 返回属性的字符串值。它没有“名称”属性。尝试移动到属性,然后获取“名称”属性。

    【讨论】:

    • “移动属性”是什么意思?我知道 GetAttribute() 返回属性的字符串值...我问是否有办法获取每个属性的“id”。
    • 我看到约翰有上面的答案。读者。移动到属性(i)。他们读者。名字应该这样做。
    猜你喜欢
    • 2013-07-11
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 2012-06-21
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多