2012-02-28 13 views
-2

このXMLファイルをオブジェクトに解析して、収集した情報を使用しようとしています。私はXMLの例を添付しています。 XDocumentはxml情報で埋め尽くされますが、私が望む情報を得ることはできません。誰かが私を助けることができる、私はこれに新しいですか?解析XMLが機能しない

編集 - 私が探しているフィールドが表示されていないからといって、それが存在しないというわけではありません。私はすべての値を二重にチェックしました、それらは存在します、ビルオブジェクトは非常に大きいので、私はそれの一部を入れます。

例のXML

<results> 


<count type="integer">13683</count> 
    <bills type="array"> 
    <bill> 
     <abbreviated type="boolean">false</abbreviated> 
     <actions type="array"> 
     <action> 
      <type>vote</type> 
      <acted_at type="datetime">2010-12-22T12:00:00Z</acted_at> 
      <text>Introduced in the Senate, read twice, considered, read the third time, and passed without amendment by Unanimous Consent.</text> 
     </action> 
     <action> 
      <type>action</type> 
      <acted_at type="datetime">2010-12-22T12:00:00Z</acted_at> 
      <text>Message on Senate action sent to the House.</text> 
     </action> 
     <action> 
      <type>action</type> 
      <acted_at type="datetime">2010-12-22T21:05:00Z</acted_at> 
      <text>Received in the House.</text> 
     </action> 
     <action> 
      <type>action</type> 
      <acted_at type="datetime">2010-12-22T22:10:00Z</acted_at> 
      <text>Held at the desk.</text> 
     </action> 
     </actions> 
     <awaiting_signature type="boolean">false</awaiting_signature> 
     <bill_id>s4053-111</bill_id> 
     <bill_type>s</bill_type> 
     <chamber>senate</chamber> 
     <code>s4053</code> 
     <committees></committees> 
     <cosponsor_ids type="array"> 
     <cosponsor_id>S000663</cosponsor_id> 
     </cosponsor_ids> 

私のコード(私は子孫として "法案" と "請求書" の両方を試してみました。)

var tutorials = from tutorial in xmlDoc.Descendants("bills") 
          select new 
          { 
           SponsorID = tutorial.Element("sponsor_id").Value, 
           SponsorFirstName = tutorial.Element("sponsor").Element("first_name").Value, 
           SponsorLastName = tutorial.Element("sponsor").Element("last_name").Value, 
           LastActionText = tutorial.Element("last_action").Element("text").Value, 
           BillNumber = tutorial.Element("number").Value, 
           BillType = tutorial.Element("bill_type").Value, 
           Enacted = tutorial.Element("enacted").Value, 
           EnactedDateTime = tutorial.Element("enacted_at").Value, 
           CongressSession = tutorial.Element("session").Value, 
           HousePassageResult = tutorial.Element("house_passage_result").Value, 
           HousePassageDateTime = tutorial.Element("house_passage_result_at").Value, 
           SenatePassageResult = tutorial.Element("senate_passage_result").Value, 
           SenatePassageDateTime = tutorial.Element("senate_passage_result_at").Value, 
           ShortTitle = tutorial.Element("short_title").Value, 
          }; 
+2

あなたのXMLは切り捨てられますか? – BrokenGlass

+0

これは間違ったxmlファイルです。他のファイルを確認してください。 –

答えて

4

sponsor_idsponsorまたはfirst_nameどちらもありますあなたのXMLは基本的にあなたのコードが期待するものとはまったく異なります。これは "請求書"と "請求書"に関係なく機能しません。

+1

実際には、私はすべての値を二重にチェックしていますが、それらは存在しています.Billオブジェクトは非常に大きいので、ここにはその一部しか入れません。これらの要素が存在しないとしても、依然として請求要素を取り戻す必要があります。 –

+0

いいえ、それはあなたの 'select new..'の中にいきなり例外をスローします - 必要な要素がすべてあることを確認しなければなりません。最初のクエリで 'bill'になっているようです。 'select new'の中の最初の行にブレークポイントを設定し、そこから移動します。 – BrokenGlass

+0

あなたの権利は、私はテストするために1つのフィールドだけにカットし、結果と一緒に戻った。私はそれらのフィールドのいくつかはオプションであり、表示されないかもしれないと思うので、私はそれらがその請求書に存在するかどうかをチェックする必要があります。 –

関連する問題