简体   繁体   English

使用linq从xml获取特定数据

[英]Getting specific data from xml using linq

could you help to get specific data from below XML. 您能否帮助从XML下面获取特定数据。

i need below field from relational nodes, 我需要关系节点的以下字段,

Thanks for your help ! 谢谢你的帮助 !

tva:ProgramInformationTable tva:ProgramInformationTable

tva:Title type="main" tva:Genre href= tva:标题类型=“ main” tva:Genre href =

tva:ProgramLocationTable tva:ProgramLocationTable

tva:PublishedStartTime tva:PublishedStartTime

they have relation on crid="............." 他们对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>

This can be a starting point. 这可能是一个起点。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM