动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 .Net FrameWork SDK文档的例子演示

作者:未知 来源:CSDN 
阅读 134 人次 , 2008-5-9 16:37:00 

XmlDocument.CreateAttribute 效果演示

using System;
using System.IO;
using System.Xml;

namespace CreateAttribute
{
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class Class1
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: 在此处添加代码以启动应用程序
   //
   XmlDocument doc = new XmlDocument();
   doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
    "<title>Pride And Prejudice</title>" +
    "</book>");

   //Create an attribute.
   XmlAttribute attr = doc.CreateAttribute("publisher");
   attr.Value = "WorldWide Publishing";
         
   //Add the new node to the document.
   doc.DocumentElement.SetAttributeNode(attr);
       
   Console.WriteLine("Display the modified XML...");       
   doc.Save(Console.Out);
  }
 }
}


效果如下:
Display the modified XML...
<?xml version="1.0" encoding="gb2312"?>
<book genre="novel" ISBN="1-861001-57-5" publisher="WorldWide Publishing">
  <title>Pride And Prejudice</title>
</book>Press any key to continue

XmlDocument.CreateNode 方法效果演示

using System;
using System.Xml;

namespace CreateNode
{
 /// <summary>
 /// Class1 的摘要说明。
 /// </summary>
 class Class1
 {
  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: 在此处添加代码以启动应用程序
   //
   XmlDocument doc = new XmlDocument();
   doc.LoadXml("<book>" +
    "  <title>Oberon's Legacy</title>" +
    "  <price>5.95</price>" +
    "</book>");
 
   // Create a new element node.
   XmlNode newElem;
   newElem = doc.CreateNode(XmlNodeType.Element, "pages", ""); 
   newElem.InnerText = "290";
    
   Console.WriteLine("Add the new element to the document...");
   XmlElement root = doc.DocumentElement;
   root.AppendChild(newElem);
    
   Console.WriteLine("Display the modified XML document...");
   Console.WriteLine(doc.OuterXml);
  }
 }
}

效果:
Add the new element to the document...
Display the modified XML document...
<book><title>Oberon's Legacy</title><price>5.95</price><pages>290</pages></book>

  
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:.NET Framework Namespaces
· 下一篇:.NET 数据访问体系结构指南一
· 发送信息页面send.asp--基于web的QQ程序
· Microsoft .NET 框架常见问题 (二)
· 和数据源联机--Connection 物件简介
· 10天学会ASP.net之第十天
· asp.net中的vb7中如何调用dll中的函数


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077