0

私はGmailからのxmlフィードをそのまま持っています:

<feed version="0.3">
    <title>Gmail - Inbox for bagee18@gmail.com</title>
    <tagline>New messages in your Gmail Inbox</tagline>
    <fullcount>9</fullcount>
    <link rel="alternate" href="http://mail.google.com/mail" type="text/html"/>
    <modified>2012-07-19T02:43:55Z</modified>
    <entry>
      <title>$50 or $100 Nightly Resort Credit and Room Upgrade</title>
      <summary>Add to Address Book | Update email address Marriott® FIND A HOTEL EXPLORE  PLAN MARRIOTT REWARDS</summary>
      <link rel="alternate" href="http://.google.com" type="text/html"/><modified>2012-07-19T01:23:00Z</modified>
      <issued>2012-07-19T01:23:00Z</issued>
      <id>tag:gmail.google.com,2004:1407882080256681207</id>
      <author>
          <name>Marriott</name>
          <email>Marriott@marriott-email.com</email>
      </author>
    </entry>
    <entry>
      <title>Tim Anderson's ITWriting » Blog Archive Resort » Moving a database from on-premise SQL Server to SQL Azure: some hassle</title>
      <summary>Tim Anderson's ITWriting Tech writing blog Home Articles Reviews Gadget Writing Forthcoming</summary>
      <link rel="alternate" href="http://google.comen" type="text/html"/><modified>2012-07-19T00:55:25Z</modified>
      <issued>2012-07-19T00:55:25Z</issued>
      <id>tag:gmail.google.com,2004:1407880344364808586</id>
        <author>
          <name>me</name>
          <email>bagee18@gmail.com</email>
        </author>
    </entry>          

そのようなLinqPadクエリを作成しました:

XDocument xmlDoc = XDocument.Load(@"C:\Users\Brad Agee\Documents\feeds.xml");

var q = from c in xmlDoc.Descendants("entry")
where c.Element("title").Value.ToLower().Contains("resort")
select new {
name = c.Element("title").Value,
url = ??,
email ??
};

q.Dump();

タグのhref属性の値をプロパティに抽出し、属性の値をプロパティに抽出するにはどうすればよいですか?linkurlemailemail

4

1 に答える 1

1

良い。href は要素リンクの属性です。そう

c.Element("link").Attribute("href")

email は要素 author の要素です

そう

c.Element("auhtor").Element("email").Value

最後に

select new
{
    name = c.Element("title").Value,
    url = c.Element("link").Attribute("href").Value,
    email = c.Element("author").Element("email").Value 
};
于 2012-07-19T12:06:36.880 に答える