欢迎光临
我们一直在努力

.Net FrameWork SDK文档的例子演示-.NET教程,.NET Framework

建站超值云服务器,限时71元/月

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>oberons 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>oberons legacy</title><price>5.95</price><pages>290</pages></book>

press any key to continue

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » .Net FrameWork SDK文档的例子演示-.NET教程,.NET Framework
分享到: 更多 (0)