i am trying to parse this xml file into an object to use the information it gathers. I am attaching an example of the xml. The XDocument fills with the xml information but it is not able to get the information i am wanting. Can someone help me, i’m new to this?
Edit- Just because you don’t see a field that i am looking for doesn’t mean it doesn’t exist. I double checked all values, they do exist, the Bill object is very large so i only put a portion of it.
Example 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>
My code (I have tried both “bill” and “bills” as the descendant.)
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,
};
There is neither a
sponsor_idnor asponsoror afirst_nameelement in your Xml (and so on), so basically your Xml is completely different from what your code expects – this cannot work, regardless of “bill” and “bills”.