1

XmlDocumentに対して単純なLINQクエリを作成していますが、「型引数を明示的に指定してみてください」というエラーが発生します。これが私のC#コードです:

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;

xmlは次のようになります。

<?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>

.Descendantsを最初に呼び出すと、エラーが発生します。何が間違っているのかわかりません。

どんな助けでもいただければ幸いです。

ありがとう!

スーザン

4

1 に答える 1

1

あなたはを使用しXmlDocumentていますが、メソッドを使用しようとしていDescendantsます...そして私はあなたが考えていることを期待しXDocument.Descendantsています。

LINQ to XMLの代わりに使用したい理由はありますか?XmlDocumentミキシングとマッチングは理想的ではありません...

最初の数行を次のように変更するだけです。

// Variable name casing changed to be more idiomatic
var document = XDocument.Load(xmlFilePath);
于 2012-11-12T14:54:06.007 に答える