0

繰り返しアイテムをxmlファイルにする必要があります。「アイテム」内には、タイトル、発行日、説明、dc:creator などのフィールドがあり、repeatwp:comment があります...以下の xml ファイルを参照してください..

<channel>
    <item>
        <title>What Messed With My Head: Summit 2011</title>
        <link>http://www.wcablog.com/2011/08/what-messed-with-my-head-summit-2011/</link>
        <pubDate>Fri, 26 Aug 2011 09:10:04 +0000</pubDate>
        <dc:creator>willowcreekassociation</dc:creator>
        <guid isPermaLink="false">http://www.wcablog.com/?p=1706</guid>
        <description></description>
        <content:encoded>
            <![CDATA[text here]]>
        </content:encoded>
        <wp:comment>
            <wp:comment_id>1016</wp:comment_id>
            <wp:comment_author><![CDATA[]]></wp:comment_author>
            <wp:comment_author_email>thelmabowlen@gmail.com</wp:comment_author_email>
            <wp:comment_author_url></wp:comment_author_url>
            <wp:comment_author_IP></wp:comment_author_IP>
            <wp:comment_date>2011-08-26 20:13:00</wp:comment_date>
            <wp:comment_content><![CDATA[some text ]]></wp:comment_content>
        </wp:comment>
        <wp:comment>
            <wp:comment_id>1016</wp:comment_id>
            <wp:comment_author><![CDATA[]]></wp:comment_author>
            <wp:comment_author_email>thelmabowlen@gmail.com</wp:comment_author_email>
            <wp:comment_author_url></wp:comment_author_url>
            <wp:comment_author_IP></wp:comment_author_IP>
            <wp:comment_date>2011-08-26 20:13:00</wp:comment_date>
            <wp:comment_content><![CDATA[some text ]]></wp:comment_content>
        </wp:comment>
    </item>
    <item>
        <title>What Messed With My Head: Summit 2011</title>
        <link>http://www.wcablog.com/2011/08/what-messed-with-my-head-summit-2011/</link>
        <pubDate>Fri, 26 Aug 2011 09:10:04 +0000</pubDate>
        <dc:creator>willowcreekassociation</dc:creator>
        <guid isPermaLink="false">http://www.wcablog.com/?p=1706</guid>
        <description></description>
        <content:encoded>
            <![CDATA[text here]]>
        </content:encoded>
    </item>
    <item>
        <title>What Messed With My Head: Summit 2011</title>
        <link>http://www.wcablog.com/2011/08/what-messed-with-my-head-summit-2011/</link>
        <pubDate>Fri, 26 Aug 2011 09:10:04 +0000</pubDate>
        <dc:creator>willowcreekassociation</dc:creator>
        <guid isPermaLink="false">http://www.wcablog.com/?p=1706</guid>
        <description></description>
        <content:encoded>
            <![CDATA[text here]]>
        </content:encoded>
        <wp:comment></wp:comment>
        <wp:comment></wp:comment>
    </item>
</channel>

次のコードを使用してxmlを読み取ります..

XDocument xDoc = XDocument.Load("willowcreekassociationblog.wordpress.xml");

        var list = xDoc.Descendants("Occurrence")
        .Select(o => new List.XMLList
        {
            title = (string)o.Element("title"),
            URL = (string)o.Element("link"),
            Descr = (string)o.Element("Description"),
            StartDate = (DateTime)o.Element("pubdate"),
        })
        .ToList();

しかし、上記のコードで wp:comment を読む方法がわかりません...これを行う方法を誰か助けてもらえますか??

4

1 に答える 1

0

あなたはデータで何をしたいのかを言っていないので、質問に答えるのは難しいです。wpまた、名前空間エイリアスが定義されている場所も示していませんが、ちょっと...

あなたはあなたの電話の中で、このようなものが欲しいです:Select

Comments = o.Elements(wp + "comment")
            .Select(comment => Comment.FromXElement(comment))
            .ToList();

ドメインオブジェクト内に、変換を実行できる静的メソッドを指定すると便利です。これにより、XElement状況がより明確になります。

FromXElementその場合、次のようになります。

public static Comment FromXElement(XElement x)
{
    return new Comment((int) x.Element(wp + "comment_id"),
                       (string) x.Element(wp + "author"),
                       ...);
}
于 2012-07-25T20:18:24.960 に答える