分析XML不起作用
本文关键字:不起作用 XML 分析 | 更新日期: 2023-09-27 18:26:01
我正试图将这个xml文件解析为一个对象,以使用它收集的信息。我附上一个xml的例子。XDocument填充了xml信息,但它无法获得我想要的信息。有人能帮我吗,我是新手?
编辑-你没有看到我要找的字段并不意味着它不存在。我仔细检查了所有的值,它们确实存在,Bill对象很大,所以我只放了一部分。
示例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>
我的代码(我已经尝试了"bill"answers"bills"作为子代。)
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,
};
Xml中既没有sponsor_id
,也没有sponsor
或first_name
元素(依此类推),因此基本上,Xml与代码所期望的完全不同——无论"bill"answers"bills"如何,这都无法工作。