.Net FrameWork SDK文档的例子演示

樱桃芽的孤独灾

樱桃芽的孤独灾

2016-01-29 13:33

.Net FrameWork SDK文档的例子演示, .Net FrameWork SDK文档的例子演示
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'" +
    "<titlePride 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"
  <titlePride And Prejudice</title
</bookPress any key to continue

XmlDocument.CreateNode 方法效果演示

using System;
using System.Xml;

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com)

namespace CreateNode
{
 /// <summary
 /// Class1 的摘要说明。
 /// </summary
 class Class1
 {
  /// <summary
  /// 应用程序的主入口点。
  /// </summary
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: 在此处添加代码以启动应用程序
   //
   XmlDocument doc = new XmlDocument();
   doc.LoadXml("<book" +
    "  <titleOberon's Legacy</title" +
    "  <price5.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<titleOberon's Legacy</title<price5.95</price<pages290</pages</book

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com)

Press any key to continue

展开更多 50%)
分享

猜你喜欢

.Net FrameWork SDK文档的例子演示

电脑网络
.Net FrameWork SDK文档的例子演示

.NET Framework与.NET Framework SDK有什么不同?

Web开发
.NET Framework与.NET Framework SDK有什么不同?

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Nucleus.MockAOP.Net:OpenSource .Net AOP FrameWork

电脑网络
Nucleus.MockAOP.Net:OpenSource .Net AOP FrameWork

.Net Framework Beta 2 初步介绍

电脑网络
.Net Framework Beta 2 初步介绍

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

与Visual Basic .NET一起使用.NET Framework

vb
与Visual Basic .NET一起使用.NET Framework

.NET Framework 安装失败的解决办法

电脑网络
.NET Framework 安装失败的解决办法

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

《部落战争》高杯屌丝流战术思路解析

《部落战争》高杯屌丝流战术思路解析

Flash制作空战游戏(4)

Flash制作空战游戏(4)
下拉加载更多内容 ↓