请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
.NET Framework
XNode 类
XNode 方法

  开启低带宽视图
Members FilterMembers Filter
Frameworks FilterFrameworks Filter
此页面仅适用于
Microsoft Visual Studio 2008/.NET Framework 3.5

同时提供下列产品的其他版本:
.NET Framework 类库
XNode..::.ReplaceWith 方法

更新:2007 年 11 月

使用指定的内容替换此节点。

  名称说明
ReplaceWith(Object) 使用指定的内容替换此节点。
ReplaceWith(array<Object>[]()[]) 使用指定的内容替换此节点。
页首

有关可以传递到此函数的有效内容的详细信息,请参见 XElement 和 XDocument 对象的有效内容

此方法将引发 ChangedChanging 事件。

下面的示例使用此方法将节点的内容替换为不同内容。

C#
XElement xmlTree = new XElement("Root",
    new XElement("Child1", "child1 content"),
    new XElement("Child2", "child2 content"),
    new XElement("Child3", "child3 content"),
    new XElement("Child4", "child4 content"),
    new XElement("Child5", "child5 content")
);
XElement child3 = xmlTree.Element("Child3");
child3.ReplaceWith(
    new XElement("NewChild", "new content")
);
Console.WriteLine(xmlTree);
Visual Basic
Dim xmlTree As XElement = _ 
        <Root>
            <Child1>child1 content</Child1>
            <Child2>child2 content</Child2>
            <Child3>child3 content</Child3>
            <Child4>child4 content</Child4>
            <Child5>child5 content</Child5>
        </Root>

Dim child3 As XElement = xmlTree.<Child3>(0)
child3.ReplaceWith(<NewChild>new content</NewChild>)
Console.WriteLine(xmlTree)

该示例产生下面的输出:

<Root>
  <Child1>child1 content</Child1>
  <Child2>child2 content</Child2>
  <NewChild>new content</NewChild>
  <Child4>child4 content</Child4>
  <Child5>child5 content</Child5>
</Root>
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker