c# - LINQ-To-XML Query on Mulitple Identical Elements -


i new linq , xml , trying work existing large 500k line xml file has same structure xml below. have figured out how test multiple null xelements totally stuck on how search multiple identical xelements.

how linq return contacts work google?

thank in advanced.

void main() { xdocument addressbook = createaddressbookxml();  var query =         contact in addressbook.descendants("contact")         let companyelement = contact.element("company")          companyelement != null         let companyname    = companyelement.descendants("companyname")         companyname != null && companyname == "google"         select contact;   console.write(query);  }   public xdocument createaddressbookxml() {     xdocument result =       new xdocument(         new xcomment("my phone book"),         new xelement("phonebook",           new xcomment("my friends"),           new xelement("contact",             new xattribute("name", "ralph"),             new xelement("homephone", "555-234-4567"),             new xelement("cellphone", "555-345-75656"),             new xelement("company",                 new xelement("companyname","ralphs web design"),                 new xelement("companyname","google")             )         ),           new xelement("contact",             new xattribute("name", "dave"),             new xelement("homephone", "555-756-9454"),             new xelement("cellphone", "555-762-1546"),             new xelement("company",                 new xelement("companyname","google")             )         ),           new xcomment("my family"),           new xelement("contact",             new xattribute("name", "julia"),             new xelement("homephone", "555-578-1053"),             new xelement("cellphone", "")         ),           new xcomment("my team"),           new xelement("contact",             new xattribute("name", "robert"),             new xelement("homephone", "555-565-1653"),             new xelement("cellphone", "555-456-2567"),             new xelement("company",                 new xelement("companyname","yahoo")                 )         )     )   );      return result; } 

var query = contacts in createaddressbookxml().root.descendants("contact")             contacts.element("company") != null &&                   contacts.element("company").elements("companyname").             firstordefault(c => c.value == "google") != null             select contacts; 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -