2011-07-20 13 views
0

VBでXLINQをいくつかやっています。結果が返されないLINQ to XMLクエリ

<?xml version="1.0" encoding="utf-8"?> 
    <Fields> 
    <typeQtyRadioButtonList>1</typeQtyRadioButtonList> 
    <cmbQtyCheck>Reject</cmbQtyCheck> 
    <optHaulierDetCheck>1</optHaulierDetCheck> 
    <txtReasonCode>1</txtReasonCode> 
    <optGenMod>0</optGenMod> 
    <optFarmRestrictions>0</optFarmRestrictions> 
    <cmbFRAction>Reject</cmbFRAction> 
    <optDisease>0</optDisease> 
    <txtDReasonCode>2</txtDReasonCode> 
    <optWithdrawl>0</optWithdrawl> 
    <txtWithdrawl>3</txtWithdrawl> 
    <optABM>0</optABM> 
    <txtCompliance>3</txtCompliance> 
    <optForm>1</optForm> 
    </Fields> 

そして、私が使用していますこれを行うには:各用の実装を残し...

Dim _ControlValueCollections = From _ControlValueCollection In _Xmlx.Descendants("Fields") _ 
            Select _Qstn1Response = _ControlValueCollection.Element("typeQtyRadioButtonList").Value, _ 
             _Qstn2Response = _ControlValueCollection.Element("optHaulierDetCheck").Value, _ 
             _Qstn3Response = _ControlValueCollection.Element("optGenMod").Value, _ 
             _Qstn4Response = _ControlValueCollection.Element("optFarmRestrictions").Value, _ 
             _Qstn5Response = _ControlValueCollection.Element("optDisease").Value, _ 
             _Qstn6Response = _ControlValueCollection.Element("optWithdrawl").Value, _ 
             _Qstn7Response = _ControlValueCollection.Element("optABM").Value, _ 
             _Qstn8Response = _ControlValueCollection.Element("optForm").Value 

    For Each _ControlValueCollection In _ControlValueCollections 

ここに記載されているように私は基本的にXMLの小さな塊からいくつかの値をプルする必要がありますループ....

私はそれぞれのためのブレークポイントをスタックしており、コレクションには要素がありません。何か不足していますか?

編集:答えはもちろん、XDocumentではなくXElementを使用していました。

+1

'_Xmlx 'はどこで宣言して初期化しますか?それはXElementかXDocumentですか? –

+1

@ Martin Honnen:それ以上ではNDAコードを使用しているので表示できません。それはXElementです。私が今見つけたものはうまくいかない。それはXDocumentの権利である必要がありますか?答えにその理由を固執すれば、私はあなたに緑のダニを与えるでしょう。 – deanvmc

答えて

1

_Xmlx.Descendants("Fields") XContainer _XmlxFieldsという名前の子孫要素を探します。 XDocument _Xmlx = XDocument("input.xml");を実行した場合、XContainer _XmlxにはFieldsという名前の唯一の子孫要素があり、コードが機能します。 XElement _Xmlx = XElement.Load("input.xml");を実行した場合、変数_Xmlxは "フィールド"要素そのものです。

+0

乾杯、それは完璧な意味があります! – deanvmc

関連する問題