XmlDocument.CreateNode 메서드

정의

XmlNode를 만듭니다.

오버로드

CreateNode(String, String, String)

지정된 노드 형식, NameNamespaceURI가 있는 XmlNode를 만듭니다.

CreateNode(XmlNodeType, String, String)

지정된 XmlNodeType, NameNamespaceURI가 있는 XmlNode를 만듭니다.

CreateNode(XmlNodeType, String, String, String)

지정된 XmlNodeType, Prefix, NameNamespaceURI가 있는 XmlNode를 만듭니다.

CreateNode(String, String, String)

지정된 노드 형식, NameNamespaceURI가 있는 XmlNode를 만듭니다.

public:
 virtual System::Xml::XmlNode ^ CreateNode(System::String ^ nodeTypeString, System::String ^ name, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode CreateNode (string nodeTypeString, string name, string namespaceURI);
public virtual System.Xml.XmlNode CreateNode (string nodeTypeString, string name, string? namespaceURI);
abstract member CreateNode : string * string * string -> System.Xml.XmlNode
override this.CreateNode : string * string * string -> System.Xml.XmlNode
Public Overridable Function CreateNode (nodeTypeString As String, name As String, namespaceURI As String) As XmlNode

매개 변수

nodeTypeString
String

새 노드의 XmlNodeType 문자열 버전입니다. 이 매개 변수는 아래 테이블에 나열된 값 중 하나여야 합니다.

name
String

새 노드의 정규화된 이름입니다. 이름에 콜론이 포함된 경우에는 PrefixLocalName 구성 요소로 구문 분석됩니다.

namespaceURI
String

새 노드의 네임스페이스 URI입니다.

반환

XmlNode

XmlNode입니다.

예외

이름이 제공되지 않았으며 XmlNodeType에 이름이 필요합니다. 또는 nodeTypeString이(가) 아래 나열된 문자열 중 하나가 아닙니다.

예제

다음은 새 요소를 만들어 문서에 삽입하는 예제입니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book>  <title>Oberon's Legacy</title>  <price>5.95</price></book>" );
   
   // Create a new element node.
   XmlNode^ newElem = doc->CreateNode( "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 );
}

using System;
using System.Xml;

public class Sample {

  public static void Main() {

       XmlDocument doc = new XmlDocument();
       doc.LoadXml("<book>" +
                   "  <title>Oberon's Legacy</title>" +
                   "  <price>5.95</price>" +
                   "</book>");

       // Create a new element node.
       XmlNode newElem = doc.CreateNode("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);
   }
 }
Imports System.Xml

public class Sample 

  public shared sub Main() 

       Dim doc as XmlDocument = new XmlDocument()
       doc.LoadXml("<book>" & _
                   "  <title>Oberon's Legacy</title>" & _
                   "  <price>5.95</price>" & _
                   "</book>") 
 
       ' Create a new element node.
       Dim newElem as XmlNode = doc.CreateNode("element", "pages", "")  
       newElem.InnerText = "290"
     
       Console.WriteLine("Add the new element to the document...")
       Dim root as XmlElement = doc.DocumentElement
       root.AppendChild(newElem)
     
       Console.WriteLine("Display the modified XML document...")
       Console.WriteLine(doc.OuterXml)
   end sub
end class

설명

매개 변수는 nodeTypeString 대/소문자를 구분하며 다음 표의 값 중 하나여야 합니다.

nodeTypeString XmlNodeType
특성 attribute
cdatasection CDATA
주석 의견
문서 문서
documentfragment DocumentFragment
documenttype DocumentType
element 요소
entityreference EntityReference
processinginstruction ProcessingInstruction
significantwhitespace SignificantWhitespace
text 텍스트
whitespace 공백

이 메서드는 문서의 컨텍스트에서 새 개체를 만들지만 문서 트리에 새 개체를 자동으로 추가하지는 않습니다. 새 개체를 추가하려면 노드 삽입 메서드 중 하나를 명시적으로 호출해야 합니다.

다음 표에서는 W3C XML(Extensible Markup Language) 1.0 권장 사항에 따라 다른 NodeType[column] 내에서 허용되는 NodeType[row]를 보여 줍니다.

문서 DocumentType XmlDeclaration 요소 attribute 텍스트 CDATA 태그 EntityReference
Document 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
DocumentType 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
XmlDeclaration 예* 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
Element 아니요 아니요 아니요 아니요 아니요 아니요 예***
Attribute 아니요 아니요 아니요 예**** 아니요 아니요 아니요 아니요 아니요
Text 아니요 아니요 아니요 아니요 아니요 아니요
CDATA 아니요 아니요 아니요 아니요 아니요 아니요 아니요 예***
Markup** 아니요 아니요 아니요 아니요 아니요 아니요 아니요
EntityReference 아니요 아니요 아니요 아니요 아니요 아니요

* XmlDeclaration 노드는 문서 노드의 첫 번째 자식이어야 합니다.

** 태그에는 ProcessingInstruction 및 주석 노드가 포함됩니다.

EntityReference 노드가 특성 노드의 자식이 아닌 경우에만 EntityReference 노드에서 요소 및 CDATA 노드가 허용됩니다.

특성은 요소 노드의 자식이 아닙니다. 특성은 요소 노드에 속하는 특성 컬렉션 내에 포함됩니다.

이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

적용 대상

CreateNode(XmlNodeType, String, String)

지정된 XmlNodeType, NameNamespaceURI가 있는 XmlNode를 만듭니다.

public:
 virtual System::Xml::XmlNode ^ CreateNode(System::Xml::XmlNodeType type, System::String ^ name, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode CreateNode (System.Xml.XmlNodeType type, string name, string namespaceURI);
public virtual System.Xml.XmlNode CreateNode (System.Xml.XmlNodeType type, string name, string? namespaceURI);
abstract member CreateNode : System.Xml.XmlNodeType * string * string -> System.Xml.XmlNode
override this.CreateNode : System.Xml.XmlNodeType * string * string -> System.Xml.XmlNode
Public Overridable Function CreateNode (type As XmlNodeType, name As String, namespaceURI As String) As XmlNode

매개 변수

type
XmlNodeType

새 노드의 XmlNodeType입니다.

name
String

새 노드의 정규화된 이름입니다. 이름에 콜론이 포함되어 있으면 PrefixLocalName 구성 요소로 구문 분석됩니다.

namespaceURI
String

새 노드의 네임스페이스 URI입니다.

반환

XmlNode

XmlNode입니다.

예외

이름이 제공되지 않았으며 XmlNodeType에 이름이 필요합니다.

예제

다음 예제에서는 새 요소를 만들고 XML 문서에 삽입합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book genre='novel' ISBN='1-861001-57-5'><title>Pride And Prejudice</title></book>" );
   
   //Create a new node and add it to the document.
   XmlNode^ elem = doc->CreateNode( XmlNodeType::Element, "price", nullptr );
   elem->InnerText = "19.95";
   doc->DocumentElement->AppendChild( elem );
   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()
  {
    //Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
                "<title>Pride And Prejudice</title>" +
                "</book>");

    //Create a new node and add it to the document.
    XmlNode elem = doc.CreateNode(XmlNodeType.Element, "price", null);
    elem.InnerText = "19.95";
    doc.DocumentElement.AppendChild(elem);

    Console.WriteLine("Display the modified XML...");
    doc.Save(Console.Out);
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create the XmlDocument.
        Dim doc As New XmlDocument()
        doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
                    "<title>Pride And Prejudice</title>" & _
                    "</book>")
        
        'Create a new node and add it to the document.
        Dim elem As XmlNode = doc.CreateNode(XmlNodeType.Element, "price", Nothing)
        elem.InnerText = "19.95"
        doc.DocumentElement.AppendChild(elem)
        
        Console.WriteLine("Display the modified XML...")
        doc.Save(Console.Out)
    End Sub
End Class

설명

이 메서드는 문서의 컨텍스트에서 새 개체를 만들지만 문서 트리에 새 개체를 자동으로 추가하지는 않습니다. 새 개체를 추가하려면 노드 삽입 메서드 중 하나를 명시적으로 호출해야 합니다.

다음 표에서는 W3C XML(Extensible Markup Language) 1.0 권장 사항에 따라 다른 NodeType[column] 내에서 허용되는 NodeType[row]를 보여 줍니다.

문서 DocumentType XmlDeclaration 요소 attribute 텍스트 CDATA 태그 EntityReference
Document 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
DocumentType 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
XmlDeclaration 예* 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
Element 아니요 아니요 아니요 아니요 아니요 아니요 예***
Attribute 아니요 아니요 아니요 예**** 아니요 아니요 아니요 아니요 아니요
Text 아니요 아니요 아니요 아니요 아니요 아니요
CDATA 아니요 아니요 아니요 아니요 아니요 아니요 아니요 예***
Markup** 아니요 아니요 아니요 아니요 아니요 아니요 아니요
EntityReference 아니요 아니요 아니요 아니요 아니요 아니요

* XmlDeclaration 노드는 문서 노드의 첫 번째 자식이어야 합니다.

** 태그에는 ProcessingInstruction 및 주석 노드가 포함됩니다.

EntityReference 노드가 특성 노드의 자식이 아닌 경우에만 EntityReference 노드에서 요소 및 CDATA 노드가 허용됩니다.

특성은 요소 노드의 자식이 아닙니다. 특성은 요소 노드에 속하는 특성 컬렉션 내에 포함됩니다.

이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

적용 대상

CreateNode(XmlNodeType, String, String, String)

지정된 XmlNodeType, Prefix, NameNamespaceURI가 있는 XmlNode를 만듭니다.

public:
 virtual System::Xml::XmlNode ^ CreateNode(System::Xml::XmlNodeType type, System::String ^ prefix, System::String ^ name, System::String ^ namespaceURI);
public virtual System.Xml.XmlNode CreateNode (System.Xml.XmlNodeType type, string prefix, string name, string namespaceURI);
public virtual System.Xml.XmlNode CreateNode (System.Xml.XmlNodeType type, string? prefix, string name, string? namespaceURI);
abstract member CreateNode : System.Xml.XmlNodeType * string * string * string -> System.Xml.XmlNode
override this.CreateNode : System.Xml.XmlNodeType * string * string * string -> System.Xml.XmlNode
Public Overridable Function CreateNode (type As XmlNodeType, prefix As String, name As String, namespaceURI As String) As XmlNode

매개 변수

type
XmlNodeType

새 노드의 XmlNodeType입니다.

prefix
String

새 노드의 접두사입니다.

name
String

새 노드의 지역 이름입니다.

namespaceURI
String

새 노드의 네임스페이스 URI입니다.

반환

XmlNode

XmlNode입니다.

예외

이름이 제공되지 않았으며 XmlNodeType에 이름이 필요합니다.

예제

다음 예제에서는 문서에 새 요소를 추가합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<book>  <title>Oberon's Legacy</title>  <price>5.95</price></book>" );
   
   // Create a new element node.
   XmlNode^ newElem;
   newElem = doc->CreateNode( XmlNodeType::Element, "g" , "ISBN" , "https://global.ISBN/list" );
   newElem->InnerText = "1-861001-57-5";
    
   // Add the new element to the document
   XmlElement^ root = doc->DocumentElement;
   root->AppendChild( newElem );
    
   // Display the modified XML document
   Console::WriteLine( doc->OuterXml );
    
    // Output:
    // <book><title>Oberon's Legacy</title><price>5.95</price><g:ISBN xmlns:g="https://global.ISBN/list">1-861001-57-5</g:ISBN></book>
}

using System;
using System.Xml;

public class Sample {

  public static void Main() {

        // Create a new document containing information about a book
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<book>" +
                    "  <title>Oberon's Legacy</title>" +
                    "  <price>5.95</price>" +
                    "</book>");

        // Create a new element node for the ISBN of the book
        // It is possible to supply a prefix for this node, and specify a qualified namespace.
        XmlNode newElem;
        newElem = doc.CreateNode(XmlNodeType.Element, "g", "ISBN", "https://global.ISBN/list");
        newElem.InnerText = "1-861001-57-5";

        // Add the new element to the document
        XmlElement root = doc.DocumentElement;
        root.AppendChild(newElem);

        // Display the modified XML document
        Console.WriteLine(doc.OuterXml);

        //Output:
        // <book><title>Oberon's Legacy</title><price>5.95</price><g:ISBN xmlns:g="https://global.ISBN/list">1-861001-57-5</g:ISBN></book>
   }
 }
Imports System.Xml

public class Sample 

  public shared sub Main() 

        Dim doc as XmlDocument = new XmlDocument()
        doc.LoadXml("<book>" & _
                    "  <title>Oberon's Legacy</title>" & _
                    "  <price>5.95</price>" & _
                       "</book>") 
 
        ' Create a new element node.
        ' It is possible to supply a prefix for this node, and specify a qualified namespace
        Dim newElem as XmlNode
        newElem = doc.CreateNode(XmlNodeType.Element,"g", "ISBN","https://global.ISBN/list")
        newElem.InnerText = "1-861001-57-5"
     
        ' Add the new element to the document
        Dim root as XmlElement = doc.DocumentElement
        root.AppendChild(newElem)
     
        ' Display the modified XML document
        Console.WriteLine(doc.OuterXml)
        
        ' Output:
        ' <book><title>Oberon's Legacy</title><price>5.95</price><g:ISBN xmlns:g="https://global.ISBN/list">1-861001-57-5</g:ISBN></book>
   end sub
end class

설명

이 메서드는 문서의 컨텍스트에서 새 개체를 만들지만 문서 트리에 새 개체를 자동으로 추가하지는 않습니다. 새 개체를 추가하려면 노드 삽입 메서드 중 하나를 명시적으로 호출해야 합니다.

다음 표에서는 W3C XML(Extensible Markup Language) 1.0 권장 사항에 따라 다른 NodeType[column] 내에서 허용되는 NodeType[row]를 보여 줍니다.

문서 DocumentType XmlDeclaration 요소 attribute 텍스트 CDATA 태그 EntityReference
Document 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
DocumentType 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
XmlDeclaration 예* 아니요 아니요 아니요 아니요 아니요 아니요 아니요 아니요
Element 아니요 아니요 아니요 아니요 아니요 아니요 예***
Attribute 아니요 아니요 아니요 예**** 아니요 아니요 아니요 아니요 아니요
Text 아니요 아니요 아니요 아니요 아니요 아니요
CDATA 아니요 아니요 아니요 아니요 아니요 아니요 아니요 예***
Markup** 아니요 아니요 아니요 아니요 아니요 아니요 아니요
EntityReference 아니요 아니요 아니요 아니요 아니요 아니요

* XmlDeclaration 노드는 문서 노드의 첫 번째 자식이어야 합니다.

** 태그에는 ProcessingInstruction 및 주석 노드가 포함됩니다.

EntityReference 노드가 특성 노드의 자식이 아닌 경우에만 EntityReference 노드에서 요소 및 CDATA 노드가 허용됩니다.

특성은 요소 노드의 자식이 아닙니다. 특성은 요소 노드에 속하는 특성 컬렉션 내에 포함됩니다.

이 메서드는 DOM(문서 개체 모델)에 대한 Microsoft 확장입니다.

적용 대상