本文整理汇总了C#中System.Xml.Linq.XComment.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# XComment.Remove方法的具体用法?C# XComment.Remove怎么用?C# XComment.Remove使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XComment
的用法示例。
在下文中一共展示了XComment.Remove方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiUnicodeHasCorrectRepsonses
public void MultiUnicodeHasCorrectRepsonses()
{
const string str = @"<CmPossibilityList
guid='cf379f73-9ee5-4e45-b2e2-4b169666d83e'>
<Name>
<AUni
ws='en'>Genres &</AUni>
<AUni
ws='es'>Géneros &</AUni>
</Name>
</CmPossibilityList>";
var element = XElement.Parse(str);
AddBasicPropertyElementsToPossList(element);
var result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNull(result);
element.Element("Name").Add(new XAttribute("bogusAttr", "badvalue"));
result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNotNull(result);
Assert.IsTrue(result.Contains("Has unrecognized attribute(s)"));
element.Element("Name").Attributes().Remove();
element.Element("Name").Add(new XElement("extraChild"));
result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNotNull(result);
Assert.IsTrue(result.Contains("Has non-AUni child element"));
element.Element("Name").Element("extraChild").Remove();
element.Element("Name").Element("AUni").Add(new XAttribute("bogusAttr", "badValue"));
result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNotNull(result);
Assert.IsTrue(result.Contains("Has too many attributes"));
var wsAttr = element.Element("Name").Element("AUni").Attribute("ws");
wsAttr.Remove();
result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNotNull(result);
Assert.IsTrue(result.Contains("Does not have required 'ws' attribute"));
element.Element("Name").Element("AUni").Attribute("bogusAttr").Remove();
element.Element("Name").Element("AUni").Add(wsAttr);
result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNull(result);
var extraChild = new XElement("extraChild");
element.Element("Name").Element("AUni").Add(extraChild);
result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNotNull(result);
Assert.IsTrue(result.Contains("Has non-text child element"));
extraChild.Remove();
// Comment doesn't count, as trouble.
var comment = new XComment("Some comment.");
element.Element("Name").Element("AUni").Add(comment);
result = CmObjectValidator.ValidateObject(_mdc, element);
Assert.IsNull(result);
comment.Remove();
}
示例2: NodeRemove
public void NodeRemove()
{
XElement parent = new XElement("parent");
XComment child1 = new XComment("child1");
XText child2 = new XText("child2");
XElement child3 = new XElement("child3");
parent.Add(child1, child2, child3);
// Sanity check
Assert.Equal(parent.Nodes(), new XNode[] { child1, child2, child3 }, XNode.EqualityComparer);
// Remove the text.
child1.NextNode.Remove();
Assert.Equal(new XNode[] { child1, child3 }, parent.Nodes(), XNode.EqualityComparer);
// Remove the XComment.
child1.Remove();
Assert.Equal(new XNode[] { child3 }, parent.Nodes(), XNode.EqualityComparer);
// Remove the XElement.
child3.Remove();
Assert.Empty(parent.Nodes());
}
示例3: NodeRemove
/// <summary>
/// Tests Remove on Node.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
//[Variation(Desc = "NodeRemove")]
public void NodeRemove()
{
XElement parent = new XElement("parent");
XComment child1 = new XComment("child1");
XText child2 = new XText("child2");
XElement child3 = new XElement("child3");
parent.Add(child1, child2, child3);
// Sanity check
Validate.EnumeratorDeepEquals(parent.Nodes(), new XNode[] { child1, child2, child3 });
// Remove the text.
child1.NextNode.Remove();
Validate.EnumeratorDeepEquals(parent.Nodes(), new XNode[] { child1, child3 });
// Remove the XComment.
child1.Remove();
Validate.EnumeratorDeepEquals(parent.Nodes(), new XNode[] { child3 });
// Remove the XElement.
child3.Remove();
Validate.EnumeratorDeepEquals(parent.Nodes(), new XNode[] { });
}
示例4: Element6
//[Variation(Priority = 0, Desc = "XElement - text node incarnation - by touching", Param = 1)]
//[Variation(Priority = 0, Desc = "XElement - text node incarnation - by adding new node", Param = 2)]
public void Element6()
{
XElement e1 = new XElement("A", "datata");
XElement e2 = new XElement("A", "datata");
switch ((int)Variation.Param)
{
case 1:
XComment c = new XComment("hele");
e2.Add(c);
c.Remove();
break;
case 2:
break;
default:
TestLog.Compare(false, "Unexpected value - test failed");
break;
}
VerifyComparison(true, e1, e2);
}