私はこのXMLを持っています:
<Config>
<EmpFieldsMap>
<Employee>
<Field>
<Name update = "false">EmpNumber</Name>
</Field>
<Field>
<Name insert = "true">EmpName</Name>
</Field>
<Field>
<Name insert = "true">EmpDesignation</Name>
</Field>
</Employee>
</EmpFieldsMap>
</Config>
私のアプリケーションは、フィールドがこのxmlから取得されるINSERTまたはUPDATEを実行します。各タグには、上記のスニペットに示されているように、insert または update 属性が含まれます。
属性を持つすべてのタグを挿入する場合
insert = "true"
この属性を持たないタグ (この場合は「EmpNumber」) を考慮する必要があります。
更新についても同様です。
このコードは、insert 属性が true に設定されたすべてのタグを提供します。
insertTags = from p in xml.Element("Config").Element("EmpFieldsMap").Elements("Field")
where p.Element("Name").Attribute("insert") != null
&& p.Element("Name").Attribute("insert").Value == "true"
select p.Element("Name").Value;
null のチェックを削除する
insertTags = from p in xml.Element("Config").Element("EmpFieldsMap").Elements("Field")
where p.Element("Name").Attribute("insert").Value == "true"
select p.Element("Name").Value;
与える
オブジェクト参照がインスタンスに設定されていません
エラー。
属性が存在しないタグも含むクエリを作成するのに問題があります。
誰かがこれで私を助けてくれますか?
よろしく。