음이 아주을 아니지만, 이것은 주석 버전 요소를 교체하지 :
결과는 다음과 같이한다
using System;
using System.Xml.Linq;
public class Test
{
static void Main()
{
var doc = new XDocument(
new XElement("root",
new XElement("value1", "This is a value"),
new XElement("value2", "This is another value")));
Console.WriteLine(doc);
XElement value2 = doc.Root.Element("value2");
value2.ReplaceWith(new XComment(value2.ToString()));
Console.WriteLine(doc);
}
}
출력 :
<root>
<value1>This is a value</value1>
<value2>This is another value</value2>
</root>
<root>
<value1>This is a value</value1>
<!--<value2>This is another value</value2>-->
</root>
value2.ReplaceWith(new XComment(value2.ToString().Trim('<', '>')));
을 ...하지만 나는 개인적 않을 것 : eally이 주석 열고 <
및 >
을 닫으면 요소에서 사람을 대체하기를 원하는, 당신은 사용할 수 있습니다.
"ReplaceWith (...)"가 트릭을 완벽하게 수행했습니다. 감사합니다. –