Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ReadElementString缺少指令或程序集引用_C#_Xml - Fatal编程技术网

C# ReadElementString缺少指令或程序集引用

C# ReadElementString缺少指令或程序集引用,c#,xml,C#,Xml,在使用System.XML.XmlReader对象时,我似乎无法使用ReadElementString。 我得到以下错误: “System.Xml.XmlReader”不包含的定义 “ReadElementString”和无扩展方法“ReadElementString” 接受类型为“System.Xml.XmlReader”的第一个参数可能是 找到(是否缺少using指令或程序集引用?) 这是我的密码: using System; using System.Net; using System.W

在使用System.XML.XmlReader对象时,我似乎无法使用ReadElementString。 我得到以下错误:

“System.Xml.XmlReader”不包含的定义 “ReadElementString”和无扩展方法“ReadElementString” 接受类型为“System.Xml.XmlReader”的第一个参数可能是 找到(是否缺少using指令或程序集引用?)

这是我的密码:

using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Text;

public void ReadXml (XmlReader reader)
{
    this.pKidsID = reader.GetAttribute("KidsID");
    reader.MoveToContent();
    reader.ReadStartElement();
    this.FirstName = reader.ReadElementString("FirstName");
    this.Name = reader.ReadElementString("Name");
    reader.Read();
    reader.ReadEndElement();
}
下面是我的xml文件的一个示例。您能否告诉我如何使用Linq to XML读取此文件:

<?xml version="1.0" encoding="utf-8"?>
<Kids>
  <Child>
    <Name>kidone</Name>
    <FirstName>elmo</FirstName>
  </Child>
  <Child>
    <Name>kidtwo</Name>
    <FirstName>elmo</FirstName>
  </Child>
</Kids>

基东
埃尔莫
基德二
埃尔莫

检查项目引用,并将引用添加到
System.Xml.dll
文件中。因为您已经有了一个使用System.Xml的
指令,我怀疑dll没有被引用

从“解决方案资源管理器”菜单中,选择“引用”,它将显示所有引用的文件。右键单击它并选择“添加引用…”,然后添加
System.Xml.dll
文件。或者,也可以从“项目”菜单执行此操作


除此之外,您发布的代码看起来不完整,因为它不包含在类中,但我猜您没有共享完整的代码。

谢谢您回答我的问题。我会检查参考资料,我认为使用说明就足够了。参考资料很好,但仍然会给我错误。ReadElementString扩展方法是否可能在Windows Phone v7.1框架中不可用?@user717316是的,这会有所不同。WP7使用基于.NET Compact Framework的XNA/Silverlight。在MSDN上,您可以选择任何类,并根据每个类旁边显示的图标检查支持的方法(鼠标悬停以查看alt文本)。如果访问类或方法本身,在名称下面应该会看到一个“OtherVersions”下拉列表,因为您会注意到“Silverlight”不是一个选项。也就是说,LINQ to XML是受支持的,所以应该可以改用它。@user717316如果您愿意使用LINQ to XML,那么请分享一个您正在使用的XML示例(编辑您的原始帖子),我可以告诉您如何阅读它。我已经编辑了我的原始帖子。很抱歉反应太晚;-)