2012-01-04 4 views
0

私は毎日特定のテレビチャンネルの番組のリストを表示するアプリケーションに取り組んでいます。 私の問題は、私のデータを抽出しているXMLが下のフォームを持っていて、私の電話ページの上と下に日の名前(月、火、木、金)を表示したいのです選択された日の番組リスト。 "date"と "item"を同時に読むことができますが、私が読むことができるのはすべて "date"またはすべての "item"ですが、同時に両方ではありません()。 C#の:doc.Elements( "プログラム")の項目から "項目" ' VAR項目=子孫( "アイテム")WP7でxmlリストボックスを解析する

select new ProgData 
    { 
    Time = item.Element("heure").Value, 
    Title = item.Element("title").Value, 
    Photo = item.Element("image").Value, 
    Description = ((item.Element("description").Value).Length > maxLength ? (item.Element("description").Value).Substring(0, maxLength) : (item.Element("description").Value)), 

    }; ProgsListBox.ItemsSource = items;` 

"日付":

var items = from c in doc.Elements("programme").Descendants("jour") 
      select new Week() 
      { 
       Day = c.Attribute("date").Value, 
       Date = (DateTime.Parse(c.Attribute("date").Value)).DayOfWeek, 
      }; ListBoxDays.ItemsSource = items; 

XML:

<programs> 
<day date="04/01/2012"> 
    <item> 
     <id>1</id> 
     <title>PROGRAM ONE</title> 
     <image> 
     http://www.tvchannel.tv/uploads/show/thumbnails_iphone/programone-copy.png 
     </image> 
     <description> 
     <![CDATA[ Infos about my show ]]> 
     </description> 
     <corps> 
     <![CDATA[ Just more infos about my show ]]> 
     <![CDATA[more and more infos]]> 
     </corps> 
     <heure>00:00</heure> 
     <link/> 
    </item> 
    <item> 
     <id>2</id> 
     <title>PROGRAM TWO</title> 
     <image> 
     http://www.tvchannel.tv/uploads/show/thumbnails_iphone/progratwo-copy.png 
     </image> 
     <description> 
     <![CDATA[ Infos about my show ]]> 
     </description> 
     <corps> 
     <![CDATA[ Just more infos about my show ]]> 
     <![CDATA[more and more infos]]> 
     </corps> 
     <heure>06:00</heure> 
     <link/> 
    </item> 
</day> 
    <day date="05/01/2012"> 
    <item> 
     <id>1</id> 
     <title>PROGRAM ONE</title> 
     <image> 
     http://www.tvchannel.tv/uploads/show/thumbnails_iphone/programone-copy.png 
     </image> 
     <description> 
     <![CDATA[ Infos about my show ]]> 
     </description> 
     <corps> 
     <![CDATA[ Just more infos about my show ]]> 
     <![CDATA[more and more infos]]> 
     </corps> 
     <heure>00:00</heure> 
     <link/> 
    </item> 
    <item> 
     <id>2</id> 
     <title>PROGRAM TWO</title> 
     <image> 
     http://www.tvchannel.tv/uploads/show/thumbnails_iphone/progratwo-copy.png 
     </image> 
     <description> 
     <![CDATA[ Infos about my show ]]> 
     </description> 
     <corps> 
     <![CDATA[ Just more infos about my show ]]> 
     <![CDATA[more and more infos]]> 
     </corps> 
     <heure>06:00</heure> 
     <link/> 
    </item> 
</day> 

電話でのページ:あなたはDateTimeオブジェクトを持っていて、代わりに曜日を表示する必要が The expected resul

+0

あなたは曜日名にDD/MM/YYYYから日付を変換する方法や上記のXMLを解析(その過程で日付を変換)する方法を求めていますか? – LukeP

+0

私はXMLの日の部分を解析し、それを同時に変換することを求めています(私はそれを解析しているときに変換します)。 – MarTech

+0

私は同時に2つのリストボックスを解析したい:( – MarTech

答えて

0

意味しますか?

switch文のDayOfWeekのクラスを使用して、必要な文字列表現(Sun、Monなど)を取得します。

+0

しかし、どのように私のXMLからそれを抽出することができますか? – MarTech

+0

xmlを表すクラス階層を作成し、それを埋めるためにlinqを使用します。その日の曜日。http://www.switchonthecode.com/tutorials/introduction-to-linq-simple-xml-parsing – Ku6opr

0

xmlからDateTimeをDateTimeに解析し、DayOfWeekプロパティを使用するだけで済みます。

MSDN DayOfWeek

+0

あなたはそのような意味ですか: 'Day =(item.Element(" jour ")。 "日付")。値).ToString( "ddd")、 '?! – MarTech

+0

私はすべての日を読むことができません、私のコードは最初の日付だけを表示します、それは普通ですか? – MarTech

+0

@MarTechおそらく、あなたのXML解析が正しく動作しません。あなたのXMLをどのように解析しますか? – BigL