ReplaceAll Method (Object)
Collapse the table of content
Expand the table of content

XElement.ReplaceAll Method (Object)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Replaces the child nodes and the attributes of this element with the specified content.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

'Declaration
Public Sub ReplaceAll ( _
	content As Object _
)

Parameters

content
Type: System.Object
The content that will replace the child nodes and attributes of this element.

This method first removes existing content and attributes. It then adds the specified content.

This method uses snapshot semantics—that is, it creates a separate copy of the new content before replacing the contents of the current element with the new content. This means that you can query the contents of the current element and use the results of the query as the specified new content.

For more information about the valid content that can be passed to this function, see Valid Content of XElement and XDocument Objects in the .NET Framework documentation.

This method will raise the Changed and the Changing events.

The following example uses this method.


Dim output As New StringBuilder
Dim root As XElement = _
    <Root>
        <Child>child content</Child>
    </Root>

' ReplaceAll with an XElement object.
root.ReplaceAll(<NewChild>n</NewChild>)
output.Append(root)
output.Append(Environment.NewLine)

' ReplaceAll with an XAttribute object.
root.ReplaceAll(New XAttribute("NewAttribute", "n"))
output.Append(root)
output.Append(Environment.NewLine)

' ReplaceAll with a string.
root.ReplaceAll("Some text")
output.Append(root)
output.Append(Environment.NewLine)

' ReplaceAll with a double.
Dim dbl As Double = 12.345
root.ReplaceAll(dbl)
output.Append(root)
output.Append(Environment.NewLine)

' ReplaceAll with a DateTime object.
Dim dt As DateTime = New DateTime(2006, 10, 6, 12, 30, 0)
root.ReplaceAll(dt)
output.Append(root)
output.Append(Environment.NewLine)

' ReplaceAll with a string array.
' Any collection other than a collection of XElement or XAttribute objects
' are converted to strings. The strings are concatenated and added.
Dim stringArray As String() = { _
    "abc", _
    "def", _
    "ghi" _
}
root.ReplaceAll(stringArray)
output.Append(root)
output.Append(Environment.NewLine)

' ReplaceAll with an array of XElement objects.
Dim ellArray As XElement() = { _
    New XElement("NewChild1", 1), _
    New XElement("NewChild2", 2), _
    New XElement("NewChild3", 3) _
}
root.ReplaceAll(ellArray)
output.Append(root)
output.Append(Environment.NewLine)

' ReplaceAll with an array of XAttribute objects.
Dim attArray As XAttribute() = { _
New XAttribute("NewAtt1", 1), _
New XAttribute("NewAtt2", 2), _
New XAttribute("NewAtt3", 3) _
}
root.ReplaceAll(attArray)
output.Append(root)
output.Append(Environment.NewLine)


OutputTextBlock.Text = output.ToString()


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft