XmlDocument.CreateComment(String) XmlDocument.CreateComment(String) XmlDocument.CreateComment(String) XmlDocument.CreateComment(String) Method


지정된 데이터가 포함된 XmlComment를 만듭니다.Creates an XmlComment containing the specified data.

 virtual System::Xml::XmlComment ^ CreateComment(System::String ^ data);
public virtual System.Xml.XmlComment CreateComment (string data);
abstract member CreateComment : string -> System.Xml.XmlComment
override this.CreateComment : string -> System.Xml.XmlComment
Public Overridable Function CreateComment (data As String) As XmlComment

매개 변수

String String String String

XmlComment의 콘텐츠입니다.The content of the new XmlComment.


XmlComment입니다.The new XmlComment.


다음 예제에서는 주석을 만들고 XML 문서에 추가 합니다.The following example creates a comment and adds it to an XML document.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   //Create a comment.
   XmlComment^ newComment;
   newComment = doc->CreateComment( "Sample XML document" );
   //Add the new node to the document.
   XmlElement^ root = doc->DocumentElement;
   doc->InsertBefore( newComment, root );
   Console::WriteLine( "Display the modified XML..." );
   doc->Save( Console::Out );

using System;
using System.IO;
using System.Xml;

public class Sample
  public static void Main()
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +

    //Create a comment.
    XmlComment newComment;
    newComment = doc.CreateComment("Sample XML document");

    //Add the new node to the document.
    XmlElement root = doc.DocumentElement;
    doc.InsertBefore(newComment, root);

    Console.WriteLine("Display the modified XML...");        

Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    Public Shared Sub Main()
        Dim doc As New XmlDocument()
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>"  & _
        'Create a comment.
        Dim newComment As XmlComment
        newComment = doc.CreateComment("Sample XML document")
        'Add the new node to the document.
        Dim root As XmlElement = doc.DocumentElement
        doc.InsertBefore(newComment, root)
        Console.WriteLine("Display the modified XML...")
    End Sub 'Main 
End Class 'Sample


이 메서드가 문서의 컨텍스트에서 새 개체를 만들고, 있지만 추가 되지 않습니다 자동으로 새 개체를 문서 트리에입니다.Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. 새 개체를 추가 하려면 명시적으로 노드 삽입 메서드 중 하나가 호출 해야 합니다.To add the new object, you must explicitly call one of the node insert methods.

W3C에 따라 Extensible Markup Language (XML) 1.0 권장 사항, 주석 노드 EntityReference 노드 특성 노드의 자식이 아닙니다. 경우에 문서, 요소 및 EntityReference 노드 내에서 허용 됩니다.According to the W3C Extensible Markup Language (XML) 1.0 recommendation, Comment nodes are only allowed within Document, Element and EntityReference nodes, when the EntityReference node is not a child of an Attribute node.

적용 대상