用于紧凑框架的LINQ和XML [英] LINQ and XML for compact framework

查看:57
本文介绍了用于紧凑框架的LINQ和XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我目前正在使用C#在.NetCF 3.5上构建应用程序。

应用程序需要处理xml文件。我正在考虑使用LINQ

来处理XML。我写了一段代码来修改指定的

元素的值。

XmlReaderSettings settings = new

XmlReaderSettings();

settings.ConformanceLevel =

ConformanceLevel.Fragment;

settings.IgnoreWhitespace = true;

settings.IgnoreComments = true;

XmlReader reader = XmlReader.Create(inboxPath,

设置);


XElement root = XElement.Load(reader);

IEnumerable< XElementmsgs =来自el in

root.Descendants(" Message")

其中el.Element(" MessageID") .Value ==

MsgID

select el;


foreach(信息中的XElement el)

{


el.Element(" MessageStaus")。SetValue(newStatus.ToSt ring());

}

root.Save(inboxPath);


以下是我收到的错误消息:


msgs.System.Collections.Generic.IEnumerator< ; TSourc e> .Curr ent''System.Collections.Generic.IEnumerable< System.Xml .Linq.XElement>''

不包含''系统'的定义,也没有扩展方法

''系统''接受类型的第一个参数

''System.Collections.Generic.IEnumerable< System.Xml .Linq.XElement>''

可以被发现(你是否错过了使用指令或程序集

参考?)


有人可以向我解释为什么会收到这样的错误消息吗?通过

,我可以参考所有必要的dll。 (System.linq;

System.xml.linq)


是因为我使用的是紧凑的框架?我已经在

上测试了这个代码,这是一个普通的框架。工作正常。

Hi

I am currently building an application on .NetCF 3.5 in C#. The
application needs to process xml files. I am thinking about using LINQ
to process XML. I wrote a piece of code to modify the specified
element''s value.
XmlReaderSettings settings = new
XmlReaderSettings();
settings.ConformanceLevel =
ConformanceLevel.Fragment;
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XmlReader reader = XmlReader.Create(inboxPath,
settings);

XElement root = XElement.Load(reader);
IEnumerable<XElementmsgs = from el in
root.Descendants("Message")
where el.Element("MessageID").Value ==
MsgID
select el;

foreach (XElement el in msgs)
{

el.Element("MessageStaus").SetValue(newStatus.ToSt ring());
}
root.Save(inboxPath);

Here is the error message that I received :

msgs.System.Collections.Generic.IEnumerator<TSourc e>.Current ''System.Collections.Generic.IEnumerable<System.Xml .Linq.XElement>''
does not contain a definition for ''System'' and no extension method
''System'' accepting a first argument of type
''System.Collections.Generic.IEnumerable<System.Xml .Linq.XElement>''
could be found (are you missing a using directive or an assembly
reference?)

Could someone please explain to me why I get such error message? By
the way I have refference all the necessary dlls. (System.linq;
System.xml.linq)

Is it because I am using compact framework? I''ve tested this code on
a normal framework. It is working fine.

推荐答案

< lu **** @ gmail.comwrote:


< snip>
<lu****@gmail.comwrote:

<snip>

是因为我使用的是紧凑型框架?我已经在

上测试了这个代码,这是一个普通的框架。它工作正常。
Is it because I am using compact framework? I''ve tested this code on
a normal framework. It is working fine.



这确实非常奇怪 - 错误信息指向哪一行?


你能发短信但完整的程序演示了

问题?


http://www.pobox.com/~skeet/csharp/complete.html 了解详情

我的意思那个。


-

Jon Skeet - < sk *** @ pobox.com>

网站: http://www.pobox.com/~skeet

博客: http://www.msmvps.com/jon.skeet

C#深度: http://csharpindepth.com

That''s very strange indeed - what line does the error message point at?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com


4月30日,7:52 * pm,Jon Skeet [C#MVP]< sk ... @ pobox.comwrote:
On Apr 30, 7:52*pm, Jon Skeet [C# MVP] <sk...@pobox.comwrote:

*< luo ... @ gmail.comwrote:


< snip>
*<luo...@gmail.comwrote:

<snip>

是因为我正在使用紧凑的框架? *我已经在

的普通框架上测试了这段代码。 *工作正常。
Is it because I am using compact framework? *I''ve tested this code on
a normal framework. *It is working fine.



确实非常奇怪 - 错误信息指向哪一行?


你能发短信但完整的程序演示了

问题?


Seehttp://www.pobox.com/~skeet/csharp/complete.html了解

我的意思是什么。


-

Jon Skeet - < sk ... @ pobox.com>

网站: http://www.pobox.com/~双向飞碟*

博客: http:// www.msmvps.com/jon.skeet

C#深度: http ://csharpindepth.com



实际上这不是错误,我的程序仍在运行。但是,如果我

将断点设为

IEnumerable< XElementmsgs = from el in

root.Descendants(" Message")

其中el.Element(" MessageID")。值==

MsgID

select el;


声明完成后,如果我查看''msgs''的值,我会

得到这样的错误信息。

Actually it is not error, my program is still running. However, if I
place a break point at
IEnumerable<XElementmsgs = from el in
root.Descendants("Message")
where el.Element("MessageID").Value ==
MsgID
select el;

After the statement is excuted, if I look up ''msgs'' ''s value, I will
get such error message.


Wan< lu **** @ gmail.comwrote:
Wan <lu****@gmail.comwrote:

实际上这不是错误,我的程序仍在运行。但是,如果我

将断点设为

IEnumerable< XElementmsgs = from el in

root.Descendants(" Message")

其中el.Element(" MessageID")。值==

MsgID

select el;


在声明完成后,如果我查看msgs的值,我将会收到这样的错误消息。
Actually it is not error, my program is still running. However, if I
place a break point at
IEnumerable<XElementmsgs = from el in
root.Descendants("Message")
where el.Element("MessageID").Value ==
MsgID
select el;
After the statement is excuted, if I look up ''msgs'' ''s value, I will
get such error message.



在这种情况下,它听起来像是一个调试器问题而不是任何东西

else。


-

Jon Skeet - < sk *** @ pobox.com>

网站: http://www.pobox.com/~skeet

博客: http://www.msmvps.com/jon.skeet

C#深度:< a rel =nofollowhref =http://csharpindepth.comtarget =_ blank> http://csharpindepth.com

In that case it sounds like a debugger problem rather than anything
else.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com


这篇关于用于紧凑框架的LINQ和XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆