0

I have xml document like this:

<?xml version="1.0" encoding="utf-8"?>
<ymaps xmlns="http://maps.yandex.ru/ymaps/1.x" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <GeoObjectCollection>
 <metaDataProperty xmlns="http://www.opengis.net/gml">
 ... 
 </metaDataProperty>
 <featureMember xmlns="http://www.opengis.net/gml">
   <GeoObject>
    ...
        <Point xmlns="http://www.opengis.net/gml">
      <pos>0.000 0.000</pos>
    </Point>
   </GeoObject>
 </featureMember>
 </GeoObjectCollection>

How to get pos node?

I try to get node like this:

  var ss = xmlDoc.DocumentElement.SelectNodes("/ymaps/GeoObjectCollection");

But i get empty list.

So, i can get pos node with recurcive method:

 private string GetGeoPosition(XmlNode node)
    {
        if (node.Name != "GeoObjectCollection")
        {
            var nodes = node.ChildNodes;
            foreach (XmlNode nod in nodes)
            {
                GetGeoPosition(nod);
            }
        }
        ...
        return "";
    }

But it seems not right way to do it. Can i use SelectNodes method to do that? Or i shoud go recurcive?

Admiral Land
  • 2,304
  • 7
  • 43
  • 81
  • 3
    `ymaps` has a *namespace*, which you are not including in the query. Look at any number of duplicates or examples of how to specify a namespace in an XPath query. As an aside, I'd probably prefer LINQ to XML over `XmlDocument` and XPath. – Charles Mager Oct 25 '16 at 14:02
  • Possible duplicate of [XPATHS and Default Namespaces](http://stackoverflow.com/questions/11345/xpaths-and-default-namespaces) – Charles Mager Oct 25 '16 at 14:04

0 Answers0