Csharp/CSharp Tutorial/XML/Xml Comment

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Adding a new comment node to the document

<source lang="csharp">using System; using System.Xml; class MainClass {

 static void Main(string[] args)
 {
       XmlDocument xmlDoc = new XmlDocument();
       xmlDoc.LoadXml("<Record> Some Value </Record>");
       XmlNode node1 = xmlDoc.CreateComment("DOM Testing Sample");
   xmlDoc.AppendChild( node1);
   node1 = xmlDoc.CreateElement("FirstName");
   node1.InnerText = "M";
   xmlDoc.DocumentElement.AppendChild(node1);
   xmlDoc.Save(Console.Out);
 }    

}</source>

<?xml version="1.0" encoding="gb2312"?>
<Record> Some Value <FirstName>M</FirstName></Record>
<!--DOM Testing Sample-->