Excel转换为XML格式之后,用XmlDocument读取时,selectNodes和SelectSingleNode方法均找不到指定节点,原因是
需要指定命名空间,代码如下:
xml.Load(@"D:\MyDocuments\VSS\Bonus.root\Bonus\TestDB\YearBonus.xml");
XmlNamespaceManager nsmgr =new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("ab","urn:schemas-microsoft-com:office:spreadsheet");
XmlNode root = xml.DocumentElement;
XmlNode v1 = root.SelectSingleNode("//ab:Workbook/ab:Worksheet/ab:Table/ab:Row", nsmgr);
XmlNode v2 = root.SelectSingleNode("//ab:Workbook/ab:Worksheet/ab:Table/ab:Row/ab:Cell/ab:Data[text()='10001001']", nsmgr);