zoukankan      html  css  js  c++  java
  • C# 操作非标准的xml文件

    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 id="Image" left="0%" top="0%" height="75%" width="100%" fit="meet"/>       <region id="Text" left="0%" top="0%" height="25%" width="100%" fit="scroll"/>     </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); }

  • 相关阅读:
    redis 实例
    redis 常用命令
    redis sets类型及操作
    简单说说PHP优化那些事
    C# IEnumerable与IQueryable ,IEnumerable与IList ,LINQ理解Var和IEnumerable
    全文搜索引擎 elasticsearch.net
    .net 异步
    并行开发 8.用VS性能向导解剖你的程序
    并行开发 7.简要分析任务与线程池
    并行开发 6.异步编程模型
  • 原文地址:https://www.cnblogs.com/chendaoyin/p/2251590.html
Copyright © 2011-2022 走看看