Reading in XML/KML files using C#

后端 未结 5 1432
遥遥无期
遥遥无期 2021-02-03 11:28

I\'m trying to import the kml xml Google earth file into an application, but i can\'t seem to get the xDocument syntax right in order to do what i want, i\'m wondering if anyone

5条回答
  •  轮回少年
    2021-02-03 11:59

    My guess is that you've forgotten to use the namespace in your LINQ to XML queries. It's easy enough to extract the data from this:

    XNamespace ns = "http://earth.google.com/kml/2.2";
    var doc = XDocument.Load("file.xml");
    var query = doc.Root
                   .Element(ns + "Document")
                   .Elements(ns + "Placemark")
                   .Select(x => new PlaceMark // I assume you've already got this
                           {
                               Name = x.Element(ns + "name").Value,
                               Description = x.Element(ns + "description").Value,
                               // etc
                           });
    

    If that doesn't help, please post a complete example of what you've tried, and what went wrong.

提交回复
热议问题