XContainer.ReplaceNodes 메서드

정의

이 문서 또는 요소의 자식 노드를 지정된 콘텐츠로 바꿉니다.

오버로드

ReplaceNodes(Object)

이 문서 또는 요소의 자식 노드를 지정된 콘텐츠로 바꿉니다.

ReplaceNodes(Object[])

이 문서 또는 요소의 자식 노드를 지정된 콘텐츠로 바꿉니다.

예제

다음 예제에서는 두 개의 XML 트리를 만든 다음 이 메서드를 사용하여 해당 트리 중 하나의 내용을 쿼리의 결과로 바꿉니다.

XElement root = new XElement("Root",  
    new XElement("Child", 1),  
    new XElement("Child", 2),  
    new XElement("Child", 3),  
    new XElement("Child", 4),  
    new XElement("Child", 5)  
);  
root.ReplaceNodes(  
    from el in root.Elements()  
    where (int)el >= 3  
    select el  
);  
Console.WriteLine(root);  
Dim root As XElement = _   
    <Root>  
        <Child>1</Child>  
        <Child>2</Child>  
        <Child>3</Child>  
        <Child>4</Child>  
        <Child>5</Child>  
    </Root>  
root.ReplaceNodes( _  
    From el In root.Elements _  
    Where el.Value >= 3 _  
    Select el)  
Console.WriteLine(root)  

이 예제는 다음과 같은 출력을 생성합니다.

<Root>  
  <Child>3</Child>  
  <Child>4</Child>  
  <Child>5</Child>  
</Root>  

설명

이 함수에 전달할 수 있는 유효한 콘텐츠에 대한 자세한 내용은 XElement 및 XDocument 개체의 유효한 콘텐츠를 참조하세요.

이 메서드는 및 이벤트를 발생 Changed 시킬 Changing 것입니다.

이 메서드에는 스냅샷 의미 체계가 있습니다. 먼저 새 콘텐츠의 복사본을 만듭니다. 그런 다음 이 노드의 모든 자식 노드를 제거합니다. 마지막으로 새 콘텐츠를 자식 노드로 추가합니다. 즉, 자식 노드 자체에서 쿼리를 사용하여 자식 노드를 바꿀 수 있습니다.

ReplaceNodes(Object)

Source:
XContainer.cs
Source:
XContainer.cs
Source:
XContainer.cs

이 문서 또는 요소의 자식 노드를 지정된 콘텐츠로 바꿉니다.

public:
 void ReplaceNodes(System::Object ^ content);
public void ReplaceNodes (object content);
public void ReplaceNodes (object? content);
member this.ReplaceNodes : obj -> unit
Public Sub ReplaceNodes (content As Object)

매개 변수

content
Object

단순 콘텐츠가 들어 있는 콘텐츠 개체이거나 자식 노드를 바꾸는 콘텐츠 개체 컬렉션입니다.

예제

다음 예제에서는 자식 노드를 포함하는 XML 트리를 만듭니다. 그런 다음 모든 자식 노드를 단일 요소로 바꿉니다.

자식 노드를 LINQ 쿼리의 결과로 바꾸는 예제를 보려면 를 참조하세요 ReplaceNodes.

XElement root = new XElement("Root",  
    new XElement("Child", 1),  
    new XElement("Child", 2),  
    new XElement("Child", 3),  
    new XElement("Child", 4),  
    new XElement("Child", 5)  
);  
root.ReplaceNodes(  
    from el in root.Elements()  
    where (int)el >= 3  
    select el  
);  
Console.WriteLine(root);  
Dim root As XElement = _   
    <Root>  
        <Child>1</Child>  
        <Child>2</Child>  
        <Child>3</Child>  
        <Child>4</Child>  
        <Child>5</Child>  
    </Root>  
root.ReplaceNodes( _  
    From el In root.Elements _  
    Where el.Value >= 3 _  
    Select el)  
Console.WriteLine(root)  

이 예제는 다음과 같은 출력을 생성합니다.

<Root>  
  <Child>3</Child>  
  <Child>4</Child>  
  <Child>5</Child>  
</Root>  

설명

이 함수에 전달할 수 있는 유효한 콘텐츠에 대한 자세한 내용은 XElement 및 XDocument 개체의 유효한 콘텐츠를 참조하세요.

이 메서드는 및 이벤트를 발생 Changed 시킬 Changing 것입니다.

이 메서드에는 스냅샷 의미 체계가 있습니다. 먼저 새 콘텐츠의 복사본을 만듭니다. 그런 다음 이 노드의 모든 자식 노드를 제거합니다. 마지막으로 새 콘텐츠를 자식 노드로 추가합니다. 즉, 자식 노드 자체에서 쿼리를 사용하여 자식 노드를 바꿀 수 있습니다.

추가 정보

적용 대상

ReplaceNodes(Object[])

Source:
XContainer.cs
Source:
XContainer.cs
Source:
XContainer.cs

이 문서 또는 요소의 자식 노드를 지정된 콘텐츠로 바꿉니다.

public:
 void ReplaceNodes(... cli::array <System::Object ^> ^ content);
public void ReplaceNodes (params object[] content);
public void ReplaceNodes (params object?[] content);
member this.ReplaceNodes : obj[] -> unit
Public Sub ReplaceNodes (ParamArray content As Object())

매개 변수

content
Object[]

콘텐츠 개체의 매개 변수 목록입니다.

예제

다음 예제에서는 사전 및 XML 트리를 만듭니다. 그런 다음 사전을 쿼리하고 결과를 의 XElementIEnumerable<T> 투영하고 XML 트리의 내용을 쿼리 결과로 바꿉니다.

XElement root = new XElement("Root",  
    new XElement("Child", 1),  
    new XElement("Child", 2),  
    new XElement("Child", 3),  
    new XElement("Child", 4),  
    new XElement("Child", 5)  
);  
root.ReplaceNodes(  
    from el in root.Elements()  
    where (int)el >= 3  
    select el  
);  
Console.WriteLine(root);  
Dim root As XElement = _   
    <Root>  
        <Child>1</Child>  
        <Child>2</Child>  
        <Child>3</Child>  
        <Child>4</Child>  
        <Child>5</Child>  
    </Root>  
root.ReplaceNodes( _  
    From el In root.Elements _  
    Where el.Value >= 3 _  
    Select el)  
Console.WriteLine(root)  

이 예제는 다음과 같은 출력을 생성합니다.

<Root>  
  <Child>3</Child>  
  <Child>4</Child>  
  <Child>5</Child>  
</Root>  

설명

이 함수에 전달할 수 있는 유효한 콘텐츠에 대한 자세한 내용은 XElement 및 XDocument 개체의 유효한 콘텐츠를 참조하세요.

이 메서드는 및 이벤트를 발생 Changed 시킬 Changing 것입니다.

이 메서드에는 스냅샷 의미 체계가 있습니다. 먼저 새 콘텐츠의 복사본을 만듭니다. 그런 다음 이 노드의 모든 자식 노드를 제거합니다. 마지막으로 새 콘텐츠를 자식 노드로 추가합니다. 즉, 자식 노드 자체에서 쿼리를 사용하여 자식 노드를 바꿀 수 있습니다.

추가 정보

적용 대상