在.NET中操作XmlDocument
2007/1/17 23:04:46
大家想必一定都了解XML,利用XML技術來存儲數據和文檔是一件很容易的事情,.NET Framework 在它的命名空間System.Xml 就提供了一種可以很方便的操作xml的類XmlDocument,它使用起來非常容易,XmlDocument 其實就是一個簡單的樹。下面詳細的介紹XmlDocument 的使用方法。

下面是這個類中操作節點的常用方法。

// create a new node in the document object from the source node
  //and name it as "sName"
// the return value indicates success or failure
public bool AddNode(XmlNode oSource, String sName);

// same as above except that it also specifies the parent node of the
  // newly created node
// the return value indicates success or failure (returns false if the
  // parent node does not exist)
public bool AddNode(XmlNode oSource, String sName, String sParent);

// create a set of new nodes in the document object from the source node
  // list and name them as "sName"
// the return value indicates success or failure
public bool AddNodes(XmlNodeList oSourceList, String sName);

// same as above except that it also specifies the parent node of the
  // newly created nodes the return value indicates success or failure
  // (returns false if the parent node
  // does not exist)
public bool AddNodes(XmlNodeList oSourceList, String sName, String sParent);

// merge the source node into a node named "sName" in the document object
// the node named "sName" will be created if it does not exist
// the return value indicates success or failure
public bool MergeNode(XmlNode oSource, String sName);

// same as above except that it also specifies the parent node of the merged node
// the return value indicates success or failure (returns false if the parent node
  // does not exist)
public bool MergeNode(XmlNode oSource, String sName, String sParent);

下面我們給一個增加節點的例子

docVechile.xml


  
    1001
    Ford
    Escort
    1984
  
  
    1002
    Toyota
    Tercel
    1996
  
  
    1003
    Mazda
    GLC
    1985
  

docDriver.xml


  
    1
    Albert
    Einstein
  
  
    2
    Clint
    Eastwood
  
  
    3
    James
    Bond
  

下面的代碼將增加一個節點:
Dim myDoc As XMLDocumentEx = New XMLDocumentEx()
myDoc.LoadXml("")
myDoc.AddNode(docVehicle.SelectSingleNode("http://Record"), "VehicleRecord", "Data")
myDoc.AddNode(docDriver.SelectSingleNode("http://Record"), "DriverRecord", "Data")
myDoc.xml
  
     ...
    ...
    ...
    ...
  
  
    ...
    ...
    ...
  
我們也可是使用AddNodes方法把一個記錄集的所有記錄增加到節點上:Dim myDoc As XMLDocumentEx = New XMLDocumentEx()
myDoc.LoadXml(" ")
myDoc.AddNodes(docVehicle.SelectNodes("http://Record"), "VehicleRecord", " Vehicle Data")
myDoc.AddNodes(docDriver.SelectNodes("http://Record"), "DriverRecord", "DriverData")結果如下:myDoc.xml
  
    
      1001
      Ford
      Escort
      1984
    
    
      1002
    

下一頁
返回列表
返回首頁 主站蜘蛛池模板: japanese国产高清麻豆| 亚洲一级生活片| 美国经典三级版在线播放| 国产无遮挡又黄又爽又色| 99久久99久久精品国产| 少妇AV射精精品蜜桃专区| 久久久噜噜噜久久中文福利| 欧美videos另类极品| 亚洲精品国产综合久久一线 | 成人浮力影院免费看| 国内精品一区二区三区最新| 国产精品网址在线观看你懂的 | 久久99精品久久久久久不卡| 杨晨晨被老师掀裙子露内内| 亚洲第一页综合图片自拍| 精品丝袜国产自在线拍亚洲| 国产91乱剧情全集| 饭冈加奈子黑人解禁在线播放| 国产精品va在线观看无| 777xxxxx欧美| 在线免费黄色网址| jzzjzz免费观看大片免费| 成人国产激情福利久久精品| 久久久午夜精品理论片| 晓雪老师下面好紧好湿| 亚洲人成77777在线播放网站| 欧美视频日韩视频| 亚洲蜜芽在线精品一区| 秦91在线播放第3集全球直播| 又黄又刺激视频| 老司机在线免费视频| 国产一级二级在线| 香港黄页精品视频在线| 国产成人悠悠影院| 免费成人福利视频| 国产精品久久久久三级| 1000部精品久久久久久久久 | 国产精品无码av在线播放| 91福利电影福利在线观看| 在线免费观看一级片| 99在线精品免费视频九九视|