Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. Complex LINQ to XML Query

Complex LINQ to XML Query

Scheduled Pinned Locked Moved LINQ
csharpdatabasedotnetlinqxml
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jackmejia
    wrote on last edited by
    #1

    Hello, I have been trying to come up with a set of records from an XML file based on a LINQ to XML query. this is the XML File. <Movies>    <Movie Code="{45CA6849-7DD8-44D7-BA10-2A09227A6A3B}" Title="Il buono, il brutto, il cattivo." ReleaseDate="12/29/1967" Genre="Western" ForRent="True" Price="5">       <Plot>A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.</Plot>       <Directors>          <Artist FirstName="Sergio" LastName="Leone" />       </Directors>       <Cast>          <Actor Role="Tuco">             <Artist FirstName="Eli" LastName="Wallach" />          </Actor>          <Actor Role="Blondie">             <Artist FirstName="Clint" LastName="Eastwood" />          </Actor>          <Actor Role="Sentenza/Angel Eyes">             <Artist FirstName="Lee" LastName="Van Cleef" />          </Actor>          <Actor Role="Alcoholic Union Captain">             <Artist FirstName="Aldo" LastName="Giuffrè" />          </Actor>          <Actor Role="Father Pablo Ramirez">             <Artist FirstName="Luigi" LastName="Pistilli" />          </Actor>          <Actor Role="Maria">             <Artist FirstName="Rada" LastName="Rassimov" />          </Actor>          <Actor Role="Storekeeper">             <Artist FirstName="Enzo" LastName="Petito" />          </Actor>          <Actor Role="Mexican peon">             <Artist FirstName="Claudio" Las

    J 1 Reply Last reply
    0
    • J jackmejia

      Hello, I have been trying to come up with a set of records from an XML file based on a LINQ to XML query. this is the XML File. <Movies>    <Movie Code="{45CA6849-7DD8-44D7-BA10-2A09227A6A3B}" Title="Il buono, il brutto, il cattivo." ReleaseDate="12/29/1967" Genre="Western" ForRent="True" Price="5">       <Plot>A bounty hunting scam joins two men in an uneasy alliance against a third in a race to find a fortune in gold buried in a remote cemetery.</Plot>       <Directors>          <Artist FirstName="Sergio" LastName="Leone" />       </Directors>       <Cast>          <Actor Role="Tuco">             <Artist FirstName="Eli" LastName="Wallach" />          </Actor>          <Actor Role="Blondie">             <Artist FirstName="Clint" LastName="Eastwood" />          </Actor>          <Actor Role="Sentenza/Angel Eyes">             <Artist FirstName="Lee" LastName="Van Cleef" />          </Actor>          <Actor Role="Alcoholic Union Captain">             <Artist FirstName="Aldo" LastName="Giuffrè" />          </Actor>          <Actor Role="Father Pablo Ramirez">             <Artist FirstName="Luigi" LastName="Pistilli" />          </Actor>          <Actor Role="Maria">             <Artist FirstName="Rada" LastName="Rassimov" />          </Actor>          <Actor Role="Storekeeper">             <Artist FirstName="Enzo" LastName="Petito" />          </Actor>          <Actor Role="Mexican peon">             <Artist FirstName="Claudio" Las

      J Offline
      J Offline
      jackmejia
      wrote on last edited by
      #2

      I found the solution. :)                   movies = from movie in doc.Descendants("Movie")                               where movie.Attribute("Title").Value.Contains(title) &&                                        movie.Element("Directors").Elements("Artist").Any(dfn => dfn.Attribute("FirstName").Value.Contains(director.FirstName)) &&                                        movie.Element("Directors").Elements("Artist").Any(dln => dln.Attribute("LastName").Value.Contains(director.LastName)) &&                                        movie.Element("Cast").Elements("Actor").Any(acf => acf.Element("Artist").Attribute("FirstName").Value.Contains(actor.FirstName)) &&                                        movie.Element("Cast").Elements("Actor").Any(acl => acl.Element("Artist").Attribute("LastName").Value.Contains(actor.LastName))                               select movie; Juan Mejia

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups