I am making a simple LINQ Query against an XmlDocument and I get the “Try specifying type arguments explicitly” error. Here is my C# code:
var Document = new XmlDocument();
Document.LoadXml(XmlFilePath);
var selectedMessage = from msg in Document.Descendants("Messages").Descendants("Message")
where msg.Attribute("Code").Value == constant
select msg;
The xml looks as follows:
<?xml version="1.0" encoding="utf-8" ?>
<MessageService>
<Messages>
<Message Code="DE-01003" Section="Delphi Backend" Line="N/A" Claim="No" Constant="E_PHY_LN_INV_HCPCS" Description="Error reading HCPCS code on line %d (%s)" />
<Message Code="DE-01004" Section="Delphi Backend" Line="N/A" Claim="No" Constant="E_PHY_LN_RBRVS_FAMILY_INV_DT" Description="RunFamilyReduction: Invalid Date on claim line %d (%s)" />
<Message Code="DE-02002" Section="Delphi Backend" Line="N/A" Claim="No" Constant="E_AMB_LN_INV_HCPCS" Description="Invalid or missing HCPCS code on claim line %d (%s)" />
.
.
.
</Messages>
</MessageService>
The first call to .Descendants causes the error. I am not sure what I am doing wrong.
Any help would be appreciated.
Thanks!
Susan
You’re using
XmlDocument, but attempting to use aDescendantsmethod… and I expect you’re thinking ofXDocument.Descendants.Is there any reason you want to use
XmlDocumentinstead of LINQ to XML? Mixing and matching isn’t going to be ideal…Just change the first couple of lines to: