C#使用xmlDocument类操作非标准的xml文件,应该先引用它的命名空间

如:

<Workbook xmlns:html="urn:schemas-microsoft-com:office:spreadsheet">

  <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">

    <WindowHeight>7995</WindowHeight>

    <WindowWidth>14955</WindowWidth>

  </ExcelWorkbook>

</Workbook>

XmlDocument xmlDoc = new XmlDocument();

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:ExcelWorkbook/ab:WindowHeight", nsmgr)//按照顺序读取节点

SMIL类型的文件

<smil xmlns="http://www.w3.org/2000/SMIL20/CR/Language">   <head>     <meta name="title" content="smil"/>     <layout>       <root-layout width="100%" height="100%"/>       <region />       <region />     </layout>   </head>   <body>     <par>       <text src="0d9e3743-9909-45e6-8d62-e28ea29e8e35.txt" region="Text"/>     </par>     <par>       <img src="26495120-e3fa-47b3-b64b-a66a138da120.gif" region="Image"/>     </par>   </body> </smil>

XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(sFilePath); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable); nsmgr.AddNamespace("default", "http://www.w3.org/2000/SMIL20/CR/Language");//引用命名空间 XmlNode mNode = xmlDoc.SelectSingleNode("//default:smil/default:body", nsmgr);//按照顺序读取 for (int i = 0; i < mNode.ChildNodes.Count; i++) {       Response.Write(mNode.ChildNodes[i].FirstChild.Attributes["region"].Value); }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2021-10-26
猜你喜欢
  • 2022-12-23
  • 2022-02-18
  • 2021-05-17
  • 2022-03-09
  • 2021-08-07
  • 2021-12-25
相关资源
相似解决方案