熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

.Net FrameWork SDK文檔例子演示

2013-11-13 10:02:02  來源: .NET編程 
XmlDocumentCreateAttribute 效果演示

using System;
using SystemIO;
using SystemXml;

  namespace CreateAttribute
{
 /// <summary>
 /// Class 的摘要說明
 /// </summary>
 class Class
 {
  /// <summary>
  /// 應用程序的主入口點
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: 在此處添加代碼以啟動應用程序
   //
   XmlDocument doc = new XmlDocument();
   docLoadXml(<book genre=@#novel@# ISBN=@#@#> +
    <title>Pride And Prejudice</title> +
    </book>);

  //Create an attribute
   XmlAttribute attr = docCreateAttribute(publisher);
   attrValue = WorldWide Publishing;
         
   //Add the new node to the document
   docDocumentElementSetAttributeNode(attr);
       
   ConsoleWriteLine(Display the modified XML);       
   docSave(ConsoleOut);
  }
 }
}


效果如下
Display the modified XML
<?xml version= encoding=gb?>
<book genre=novel ISBN= publisher=WorldWide Publishing>
  <title>Pride And Prejudice</title>
</book>Press any key to continue

XmlDocumentCreateNode 方法效果演示

using System;
using SystemXml;

  namespace CreateNode
{
 /// <summary>
 /// Class 的摘要說明
 /// </summary>
 class Class
 {
  /// <summary>
  /// 應用程序的主入口點
  /// </summary>
  [STAThread]
  static void Main(string[] args)
  {
   //
   // TODO: 在此處添加代碼以啟動應用程序
   //
   XmlDocument doc = new XmlDocument();
   docLoadXml(<book> +
      <title>Oberon@#s Legacy</title> +
      <price></price> +
    </book>);
 
   // Create a new element node
   XmlNode newElem;
   newElem = docCreateNode(XmlNodeTypeElement pages ); 
   newElemInnerText = ;
    
   ConsoleWriteLine(Add the new element to the document);
   XmlElement root = docDocumentElement;
   rootAppendChild(newElem);
    
   ConsoleWriteLine(Display the modified XML document);
   ConsoleWriteLine(docOuterXml);
  }
 }
}

效果
Add the new element to the document
Display the modified XML document
<book><title>Oberon@#s Legacy</title><price></price><pages></pages></book>

  Press any key to continue


From:http://tw.wingwit.com/Article/program/net/201311/12330.html
  • 上一篇文章:

  • 下一篇文章:
  • 推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.