2012-12-17 29 views
0

從xml獲取特定數據可以幫助從下面的XML獲取特定數據。使用linq

我需要關係節點下面的字段,

感謝您的幫助!

TVA:ProgramInformationTable

TVA:標題類型= 「主」 TVA:流派HREF =

TVA:ProgramLocationTable

TVA:PublishedStartTime

它們具有關係在crid =「.............」

<?xml version="1.0" encoding="utf-8"?> 
<tva:TVAMain xmlns:tva="urn:tva:metadata:2005" xmlns:mpeg7="urn:tva:mpeg7:2005" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="tr"> 
    <tva:ProgramDescription> 

    <tva:ProgramInformationTable> 

     <tva:ProgramInformation programId="2471154983201212170000" ChannelName="13951" xmlns:tva="urn:tva:metadata:2005"> 
     <tva:BasicDescription> 
      <tva:Title type="main"><![CDATA[Krem]]></tva:Title> 
      <tva:Title type="original"></tva:Title> 
      <tva:Title type="episodeTitle"></tva:Title> 
      <tva:Title type="seriesTitle"></tva:Title> 
      <tva:Synopsis length="short"><![CDATA[Mucizeler sadece masallarda mı olur?]]></tva:Synopsis> 
      <tva:Synopsis length="long"><![CDATA[Desc]]></tva:Synopsis> 
      <tva:Genre href="urn:etsi:cs:GenreEtsiCS:2009:1.0" /> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:9004"> 
      <tva:Name><![CDATA[Dizi]]></tva:Name> 
      </tva:Genre> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:9801"> 
      <tva:Name><![CDATA[Yerli]]></tva:Name> 
      </tva:Genre> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:1.7"> 
      <tva:Name><![CDATA[Dram]]></tva:Name> 
      </tva:Genre> 
      <tva:Language type="original" closed="true"><![CDATA[tr-TR]]></tva:Language> 
      <tva:CaptionLanguage></tva:CaptionLanguage> 
     </tva:BasicDescription> 
     <tva:AVAttributes> 
      <tva:System href="urn:engin:cs:VideoFormat:SD" /> 
     </tva:AVAttributes> 
     </tva:ProgramInformation> 

     <tva:ProgramInformation programId="2471051483201212170020" ChannelName="13951" xmlns:tva="urn:tva:metadata:2005"> 
     <tva:BasicDescription> 
      <tva:Title type="main"><![CDATA[Dizi]]></tva:Title> 
      <tva:Title type="original"></tva:Title> 
      <tva:Title type="episodeTitle"></tva:Title> 
      <tva:Title type="seriesTitle"></tva:Title> 
      <tva:Synopsis length="short"><![CDATA[]]></tva:Synopsis> 
      <tva:Synopsis length="long"><![CDATA[]]></tva:Synopsis> 
      <tva:Genre href="urn:etsi:cs:GenreEtsiCS:2009:1.0" /> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:9004"> 
      <tva:Name><![CDATA[Dizi]]></tva:Name> 
      </tva:Genre> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:9801"> 
      <tva:Name><![CDATA[Yerli]]></tva:Name> 
      </tva:Genre> 
      <tva:Language type="original" closed="true"><![CDATA[tr-TR]]></tva:Language> 
      <tva:CaptionLanguage></tva:CaptionLanguage> 
      <tva:CreditsList> 
      <tva:ReleaseInformation> 
       <tva:ReleaseDate> 
       <tva:Year></tva:Year> 
       </tva:ReleaseDate> 
      </tva:ReleaseInformation> 
      </tva:CreditsList> 
     </tva:BasicDescription> 
     <tva:AVAttributes> 
      <tva:System href="urn:engin:cs:VideoFormat:SD" /> 
     </tva:AVAttributes> 
     </tva:ProgramInformation> 

     <tva:ProgramInformation programId="2471155083201212170210" ChannelName="13951" xmlns:tva="urn:tva:metadata:2005"> 
     <tva:BasicDescription> 
      <tva:Title type="main"><![CDATA[Unutulmaz]]></tva:Title> 
      <tva:Title type="original"></tva:Title> 
      <tva:Title type="episodeTitle"></tva:Title> 
      <tva:Title type="seriesTitle"></tva:Title> 
      <tva:Synopsis length="short"><![CDATA[Desc]]></tva:Synopsis> 
      <tva:Synopsis length="long"> 
      <![CDATA[Desc]]> 
      </tva:Synopsis> 
      <tva:Genre href="urn:etsi:cs:GenreEtsiCS:2009:1.0" /> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:9004"> 
      <tva:Name><![CDATA[Dizi]]></tva:Name> 
      </tva:Genre> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:9801"> 
      <tva:Name><![CDATA[Yerli]]></tva:Name> 
      </tva:Genre> 
      <tva:Genre href="urn:engin:cs:GenreSectionCS:2009:1.7"> 
      <tva:Name><![CDATA[Dram]]></tva:Name> 
      </tva:Genre> 
      <tva:Language type="original" closed="true"><![CDATA[tr-TR]]></tva:Language> 
      <tva:CaptionLanguage></tva:CaptionLanguage>   
     </tva:BasicDescription> 
     <tva:AVAttributes> 
      <tva:System href="urn:engin:cs:VideoFormat:SD" /> 
     </tva:AVAttributes> 
     </tva:ProgramInformation> 

    </tva:ProgramInformationTable> 

    <tva:ProgramLocationTable> 

     <tva:ScheduleEvent xmlns:tva="urn:tva:metadata:2005"> 
     <tva:Program crid="2471154983201212170000" /> 
     <tva:PublishedStartTime>2012-12-17T00:00:00+02:00</tva:PublishedStartTime> 
     <tva:PublishedEndTime>2012-12-17T00:20:00+02:00</tva:PublishedEndTime> 
     <tva:PublishedDuration>PT00H20M00S</tva:PublishedDuration> 
     </tva:ScheduleEvent> 

     <tva:ScheduleEvent xmlns:tva="urn:tva:metadata:2005"> 
     <tva:Program crid="2471051483201212170020" /> 
     <tva:PublishedStartTime>2012-12-17T00:20:00+02:00</tva:PublishedStartTime> 
     <tva:PublishedEndTime>2012-12-17T02:10:00+02:00</tva:PublishedEndTime> 
     <tva:PublishedDuration>PT01H50M00S</tva:PublishedDuration> 
     </tva:ScheduleEvent> 


     <tva:ScheduleEvent xmlns:tva="urn:tva:metadata:2005"> 
     <tva:Program crid="2471155083201212170210" /> 
     <tva:PublishedStartTime>2012-12-17T02:10:00+02:00</tva:PublishedStartTime> 
     <tva:PublishedEndTime>2012-12-17T03:50:00+02:00</tva:PublishedEndTime> 
     <tva:PublishedDuration>PT01H40M00S</tva:PublishedDuration> 
     </tva:ScheduleEvent>  

    </tva:ProgramLocationTable> 




    <tva:ServiceInformationTable> 
     <tva:ServiceInformation serviceId="ATV"> 
     <tva:Name>ATV</tva:Name> 
     </tva:ServiceInformation> 
    </tva:ServiceInformationTable> 



    </tva:ProgramDescription> 
</tva:TVAMain> 
+0

我試過了,戴夫。但我沒有太多時間。我希望你明白我 – Talha

回答

1

這可以是一個起點。

var xDoc = XDocument.Load(filename); 
XNamespace tva = "urn:tva:metadata:2005"; 

var pi = xDoc.Descendants(tva + "ProgramInformation") 
      .Select(p => new 
      { 
       ProgramId = p.Attribute("programId").Value, 
       ChannelName = p.Attribute("ChannelName").Value, 
       Title = p.Descendants(tva+"Title") 
         .First(a=>a.Attribute("type").Value=="main") 
         .Value 
      }) 
      .ToList(); 
+1

謝謝L.B,它的工作原理... – Talha

+0

我現在詳細檢查你的代碼,但我無法理解我可以如何獲得PublishedStartTime?它在另一張桌子?謝謝... – Talha

+0

@talhakosen是的,它是在另一個父母之下。 'xDoc.Descendants(tva +「ProgramLocationTable」).....'(或者''Descendants(tva +「ScheduleEvent」)') –