L
luowan
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<XElement> msgs = from el in
root.Descendants("Message")
where el.Element("MessageID").Value ==
MsgID
select el;
foreach (XElement el in msgs)
{
el.Element("MessageStaus").SetValue(newStatus.ToString());
}
root.Save(inboxPath);
Here is the error message that I received :
msgs.System.Collections.Generic.IEnumerator<TSource>.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.
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<XElement> msgs = from el in
root.Descendants("Message")
where el.Element("MessageID").Value ==
MsgID
select el;
foreach (XElement el in msgs)
{
el.Element("MessageStaus").SetValue(newStatus.ToString());
}
root.Save(inboxPath);
Here is the error message that I received :
msgs.System.Collections.Generic.IEnumerator<TSource>.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.