XPathNavigator.AppendChild 메서드

정의

현재 노드의 자식 노드 목록 끝에 새 자식 노드를 만듭니다.

오버로드

Name Description
AppendChild()

현재 노드의 XmlWriter 자식 노드 목록 끝에 하나 이상의 새 자식 노드를 만드는 데 사용되는 개체를 반환합니다.

AppendChild(String)

지정된 XML 데이터 문자열을 사용하여 현재 노드의 자식 노드 목록 끝에 새 자식 노드를 만듭니다.

AppendChild(XmlReader)

지정된 개체의 XML 내용을 사용하여 현재 노드의 자식 노드 목록 끝에 새 자식 노드를 XmlReader 만듭니다.

AppendChild(XPathNavigator)

지정된 노드를 사용하여 현재 노드의 자식 노드 목록 끝에 새 자식 노드를 XPathNavigator 만듭니다.

AppendChild()

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

현재 노드의 XmlWriter 자식 노드 목록 끝에 하나 이상의 새 자식 노드를 만드는 데 사용되는 개체를 반환합니다.

public:
 virtual System::Xml::XmlWriter ^ AppendChild();
public virtual System.Xml.XmlWriter AppendChild();
abstract member AppendChild : unit -> System.Xml.XmlWriter
override this.AppendChild : unit -> System.Xml.XmlWriter
Public Overridable Function AppendChild () As XmlWriter

반품

XmlWriter 현재 노드의 자식 노드 목록 끝에 새 자식 노드를 만드는 데 사용되는 개체입니다.

예외

현재 배치된 노드 XPathNavigator 는 루트 노드 또는 요소 노드가 아닙니다.

편집을 XPathNavigator 지원하지 않습니다.

예제

다음 예제에서는 메서드에서 pages 반환된 개체를 사용하여 book 파일의 첫 번째 contosoBooks.xml 요소 자식 요소 목록에 새 XmlWriter 자식 요소가 AppendChild 추가됩니다.

XmlDocument document = new XmlDocument();
document.Load("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
navigator.MoveToChild("book", "http://www.contoso.com/books");

XmlWriter pages = navigator.AppendChild();
pages.WriteElementString("pages", "100");
pages.Close();

Console.WriteLine(navigator.OuterXml);
Dim document As XmlDocument = New XmlDocument()
document.Load("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToChild("bookstore", "http://www.contoso.com/books")
navigator.MoveToChild("book", "http://www.contoso.com/books")

Dim pages As XmlWriter = navigator.AppendChild()
pages.WriteElementString("pages", "100")
pages.Close()

Console.WriteLine(navigator.OuterXml)

이 예제에서는 파일을 입력으로 사용합니다 contosoBooks.xml .

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

설명

자식 노드를 추가하면 현재 노드에 대한 자식 노드 목록의 끝에 새 노드가 추가됩니다. 예를 들어 요소에 대해 세 개의 자식 노드가 있는 경우 첫 번째 추가된 노드는 네 번째 자식 노드가 됩니다. 자식 노드가 없으면 새 자식 노드가 만들어집니다.

다음은 메서드를 사용할 때 고려해야 할 중요한 참고 사항입니다 AppendChild .

기록기에 둘 이상의 노드를 쓸 수 있습니다. 모든 노드는 현재 노드의 자식 노드 목록 끝에 추가됩니다.

적용 대상

AppendChild(String)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

지정된 XML 데이터 문자열을 사용하여 현재 노드의 자식 노드 목록 끝에 새 자식 노드를 만듭니다.

public:
 virtual void AppendChild(System::String ^ newChild);
public virtual void AppendChild(string newChild);
abstract member AppendChild : string -> unit
override this.AppendChild : string -> unit
Public Overridable Sub AppendChild (newChild As String)

매개 변수

newChild
String

새 자식 노드에 대한 XML 데이터 문자열입니다.

예외

XML 데이터 문자열 매개 변수는 .입니다 null.

현재 배치된 노드 XPathNavigator 는 루트 노드 또는 요소 노드가 아닙니다.

편집을 XPathNavigator 지원하지 않습니다.

XML 데이터 문자열 매개 변수의 형식이 잘못되었습니다.

예제

다음 예제에서는 pages 파일 내에서 첫 번째 book 요소의 자식 요소 목록에 새 contosoBooks.xml 자식 요소가 추가됩니다.

XmlDocument document = new XmlDocument();
document.Load("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
navigator.MoveToChild("book", "http://www.contoso.com/books");

navigator.AppendChild("<pages>100</pages>");

Console.WriteLine(navigator.OuterXml);
Dim document As XmlDocument = New XmlDocument()
document.Load("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToChild("bookstore", "http://www.contoso.com/books")
navigator.MoveToChild("book", "http://www.contoso.com/books")

navigator.AppendChild("<pages>100</pages>")

Console.WriteLine(navigator.OuterXml)

이 예제에서는 파일을 입력으로 사용합니다 contosoBooks.xml .

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

설명

자식 노드를 추가하면 현재 노드에 대한 자식 노드 목록의 끝에 새 노드가 추가됩니다. 예를 들어 요소에 대해 3개의 자식 노드가 있는 경우 추가된 노드는 네 번째 자식 노드가 됩니다. 자식 노드가 없으면 새 자식 노드가 만들어집니다.

새 요소 노드를 만들려면 XML 문자열 매개 변수에 모든 XML 구문을 포함합니다. 새 book 노드의 문자열은 .입니다 AppendChild("<book/>"). 현재 노드의 텍스트 노드에 텍스트 "book"을 추가하는 문자열은 다음과 같습니다 AppendChild("book"). XML 문자열에 여러 노드가 포함된 경우 모든 노드가 추가됩니다.

다음은 메서드를 사용할 때 고려해야 할 중요한 참고 사항입니다 AppendChild .

적용 대상

AppendChild(XmlReader)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

지정된 개체의 XML 내용을 사용하여 현재 노드의 자식 노드 목록 끝에 새 자식 노드를 XmlReader 만듭니다.

public:
 virtual void AppendChild(System::Xml::XmlReader ^ newChild);
public virtual void AppendChild(System.Xml.XmlReader newChild);
abstract member AppendChild : System.Xml.XmlReader -> unit
override this.AppendChild : System.Xml.XmlReader -> unit
Public Overridable Sub AppendChild (newChild As XmlReader)

매개 변수

newChild
XmlReader

XmlReader 새 자식 노드의 XML 데이터에 배치된 개체입니다.

예외

XmlReader 개체가 오류 상태이거나 닫혀 있습니다.

개체 매개 변수는 XmlReader .입니다 null.

현재 배치된 노드 XPathNavigator 는 루트 노드 또는 요소 노드가 아닙니다.

편집을 XPathNavigator 지원하지 않습니다.

개체 매개 변수의 XML 내용이 XmlReader 잘 구성되지 않았습니다.

예제

다음 예제에서는 지정된 개체를 사용하여 pages 파일에서 첫 번째 book 요소의 자식 요소 목록에 새 contosoBooks.xml 자식 요소가 XmlReader 추가됩니다. http://www.contoso.com/books XML 문서와 동일한 네임스페이스를 사용하여 새 자식 요소가 추가되도록 네임스페이스가 지정됩니다.

XmlDocument document = new XmlDocument();
document.Load("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
navigator.MoveToChild("book", "http://www.contoso.com/books");

XmlReader pages = XmlReader.Create(new StringReader("<pages xmlns=\"http://www.contoso.com/books\">100</pages>"));

navigator.AppendChild(pages);

Console.WriteLine(navigator.OuterXml);
Dim document As XmlDocument = New XmlDocument()
document.Load("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToChild("bookstore", "http://www.contoso.com/books")
navigator.MoveToChild("book", "http://www.contoso.com/books")

Dim pages As XmlReader = XmlReader.Create(New StringReader("<pages xmlns='http://www.contoso.com/books'>100</pages>"))

navigator.AppendChild(pages)

Console.WriteLine(navigator.OuterXml)

이 예제에서는 파일을 입력으로 사용합니다 contosoBooks.xml .

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

설명

자식 노드를 추가하면 현재 노드에 대한 자식 노드 목록의 끝에 새 노드가 추가됩니다. 예를 들어 요소에 대해 3개의 자식 노드가 있는 경우 추가된 노드는 네 번째 자식 노드가 됩니다. 자식 노드가 없으면 새 자식 노드가 만들어집니다.

다음은 메서드를 사용할 때 고려해야 할 중요한 참고 사항입니다 AppendChild .

  • 개체가 XmlReader XML 노드 시퀀스 위에 배치되면 시퀀스의 모든 노드가 추가됩니다.

  • AppendChild 메서드는 루트 노드 또는 요소 노드에 배치된 경우에만 XPathNavigator 유효합니다.

  • 메서드는 AppendChild .의 XPathNavigator위치에 영향을 주지 않습니다.

적용 대상

AppendChild(XPathNavigator)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

지정된 노드를 사용하여 현재 노드의 자식 노드 목록 끝에 새 자식 노드를 XPathNavigator 만듭니다.

public:
 virtual void AppendChild(System::Xml::XPath::XPathNavigator ^ newChild);
public virtual void AppendChild(System.Xml.XPath.XPathNavigator newChild);
abstract member AppendChild : System.Xml.XPath.XPathNavigator -> unit
override this.AppendChild : System.Xml.XPath.XPathNavigator -> unit
Public Overridable Sub AppendChild (newChild As XPathNavigator)

매개 변수

newChild
XPathNavigator

XPathNavigator 새 자식 노드로 추가할 노드에 배치된 개체입니다.

예외

개체 매개 변수는 XPathNavigator .입니다 null.

현재 배치된 노드 XPathNavigator 는 루트 노드 또는 요소 노드가 아닙니다.

편집을 XPathNavigator 지원하지 않습니다.

예제

다음 예제에서는 지정된 노드를 사용하여 파일에서 첫 번째 pages 요소의 자식 요소 목록에 새 book 자식 요소가 contosoBooks.xml 추가됩니다XPathNavigator. http://www.contoso.com/books XML 문서와 동일한 네임스페이스를 사용하여 새 자식 요소가 추가되도록 네임스페이스가 지정됩니다.

XmlDocument document = new XmlDocument();
document.Load("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToChild("bookstore", "http://www.contoso.com/books");
navigator.MoveToChild("book", "http://www.contoso.com/books");

XmlDocument childNodes = new XmlDocument();
childNodes.Load(new StringReader("<pages xmlns=\"http://www.contoso.com/books\">100</pages>"));
XPathNavigator childNodesNavigator = childNodes.CreateNavigator();

if(childNodesNavigator.MoveToChild("pages", "http://www.contoso.com/books"))
{
    navigator.AppendChild(childNodesNavigator);
}

Console.WriteLine(navigator.OuterXml);
Dim document As XmlDocument = New XmlDocument()
document.Load("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToChild("bookstore", "http://www.contoso.com/books")
navigator.MoveToChild("book", "http://www.contoso.com/books")

Dim childNodes As XmlDocument = New XmlDocument()

childNodes.Load(New StringReader("<pages xmlns='http://www.contoso.com/books'>100</pages>"))
Dim childNodesNavigator As XPathNavigator = childNodes.CreateNavigator()

If childNodesNavigator.MoveToChild("pages", "http://www.contoso.com/books") Then
    navigator.AppendChild(childNodesNavigator)
End If

Console.WriteLine(navigator.OuterXml)

이 예제에서는 파일을 입력으로 사용합니다 contosoBooks.xml .

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
        <title>The Autobiography of Benjamin Franklin</title>
        <author>
            <first-name>Benjamin</first-name>
            <last-name>Franklin</last-name>
        </author>
        <price>8.99</price>
    </book>
    <book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
        <title>The Confidence Man</title>
        <author>
            <first-name>Herman</first-name>
            <last-name>Melville</last-name>
        </author>
        <price>11.99</price>
    </book>
    <book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
        <title>The Gorgias</title>
        <author>
            <name>Plato</name>
        </author>
        <price>9.99</price>
    </book>
</bookstore>

설명

자식 노드를 추가하면 현재 노드에 대한 자식 노드 목록의 끝에 새 노드가 추가됩니다. 예를 들어 요소에 대해 3개의 자식 노드가 있는 경우 추가된 노드는 네 번째 자식 노드가 됩니다. 자식 노드가 없으면 새 자식 노드가 만들어집니다.

다음은 메서드를 사용할 때 고려해야 할 중요한 참고 사항입니다 AppendChild .

  • 개체가 XPathNavigator XML 노드 시퀀스 위에 배치되면 시퀀스의 모든 노드가 추가됩니다.

  • AppendChild 메서드는 루트 노드 또는 요소 노드에 배치된 경우에만 XPathNavigator 유효합니다.

  • 메서드는 AppendChild .의 XPathNavigator위치에 영향을 주지 않습니다.

적용 대상