错误:从XML获取节点值时的令牌无效

时间:2012-06-20 07:00:13

标签: c# .net

在下面的代码中,我需要获取根节点中的节点值

Root Node :   <basemap:AlterationService xmlns:basemap="http://www.xxx.com/basemap">

我需要为XmlNodeList提供节点名称,以便获取数据。 我正在使用下面的c#代码来获取值,但是,我收到错误,

'<basemap:AlterationService xmlns:basemap="http://www.xxx.com/basemap"' has an invalid token.

C#:

    XmlDocument xml = new XmlDocument();
    xml.Load("C:/Test/Sample.xml");

    string RootNode = "basemap:AlterationService xmlns:basemap=\"http://www.xxx.com/basemap\"";
     XmlNodeList xnList = xml.SelectNodes(RootNode); //Error in this line
     foreach (XmlNode xn in xnList)
     {
        ................
        ................
     }


XML : 

   <?xml version="1.0"?>
   <basemap:AlterationService xmlns:basemap="http://www.xxx.com/basemap">
      .....
      .....
   </basemap:AlterationService>

0 个答案:

没有答案