• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
张纯睿
博客园    首页    新随笔    联系   管理    订阅  订阅

如何对一xml格式的字符串分析? c#

http://topic.csdn.net/t/20021102/16/1142056.html

use   classes   in   System.Xml   namespace,   for   example   (assume   your   xml   is   in   string   s   and   it   contains   an   xmlns   definition):  
   
  <ns:vi   id="New_main"   xmlns:ns="whatever">  
  <ns:node   Expandable="checkOnce"   Selected="true"   ID="a1">  
  root<ns:node   ID="a2">  
  Node1  
          </ns:node>  
  </ns:node>  
  </ns:vi>  
   
   
  string   s   =   "................";  
   
  XmlDocument   xmldoc   =   new   XmlDocument();  
  xmldoc.LoadXml(s);  
   
  XmlNamespaceManager   xnm   =   new   XmlNamespaceManager(xmldoc.NameTable);  
  xnm.AddNamespace("ns","whatever");  
   
  XmlNode   node   =   xmldoc.SelectSingleNode("//ns:node[@ID='a1']",   xnm);  
  if   (node   !=   null)  
  {  
      XmlAttribute   att   =   xmldoc.CreateAttribute("bbi");  
      att.Value   =   "xxxxxxxxxxx";  
      node.Attributes.Append(att);  
  }


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/carl2380/archive/2010/01/17/5203421.aspx

posted @ 2011-06-29 14:35  张纯睿  阅读(139)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3