XmlDocument
CreateAttribute 效果演示
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