code_junkie

LINQ to XML gets no data with schema set

Nov 11th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. <CarsForSale xmlns="http://schemas.sharplogic.net/CarSales.xsd">
  2. <CarForSale>
  3.  
  4. XElement doc = XElement.Load(HttpContext.Current.Server.MapPath("App_Data/XML/CarsForSale.xml"));
  5.  
  6. var cars2 = from d in doc.Descendants("CarForSale")
  7. select d;
  8.  
  9. var ns = "http://schemas.sharplogic.net/CarSales.xsd";
  10. var cars2 = from d in doc.Descendants(ns + "CarForSale")
  11. select d;
  12.  
  13. var cars2 = from d in doc.Descendants()
  14. where d.Name.LocalName == "CarForSale"
  15. select d;
  16.  
  17. XNamespace ns = doc.Root.Name.Namespace;
Add Comment
Please, Sign In to add comment