111,118
社区成员
发帖
与我相关
我的任务
分享 XmlDocument xml = new XmlDocument();
XmlDeclaration del = xml.CreateXmlDeclaration("1.0", "utf-8", "");
xml.AppendChild(del);
XmlNode node = xml.CreateElement("root");
XmlCDataSection c = xml.CreateCDataSection(@"<Com Name=""COM6"" BaudRate=""115200"" DtrEnable=""True"" DataBits=""8"" Parity=""None"" StopBits=""One""/>");
node.AppendChild(c);
xml.AppendChild(node);
xml.Save(Server.MapPath("XMLFile.xml"));<?xml version="1.0" encoding="utf-8"?>
<root><![CDATA[<Com Name="COM6" BaudRate="115200" DtrEnable="True" DataBits="8" Parity="None" StopBits="One"/>]]></root>
//插入<![CDATA[]]>
XmlDocument xml = new XmlDocument();
XmlCDataSection c = xml.CreateCDataSection("xxxx");
using System;
using System.Xml;
static class Program {
static void Main(string[] args){
XmlDocument doc = new XmlDocument();
XmlElement xe = doc.CreateElement("root");
xe.InnerXml = "<Com Name=\"COM6\" BaudRate=\"115200\" DtrEnable=\"True\" DataBits=\"8\" Parity=\"None\" StopBits=\"One\" />";
doc.AppendChild(xe);
doc.Save(Console.Out);
}
}