本文整理汇总了C#中System.Xml.XmlElement.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# XmlElement.GetEnumerator方法的具体用法?C# XmlElement.GetEnumerator怎么用?C# XmlElement.GetEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlElement
的用法示例。
在下文中一共展示了XmlElement.GetEnumerator方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendChildAffectOnEnumeration
public void AppendChildAffectOnEnumeration ()
{
document.LoadXml ("<foo><child1/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
enumerator.Reset();
Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
element.AppendChild(document.CreateElement("child2"));
Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
}
示例2: Reset
public void Reset ()
{
document.LoadXml ("<foo><child1/><child2/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
enumerator.MoveNext();
enumerator.MoveNext();
Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child2", "Expected child2.");
enumerator.Reset();
enumerator.MoveNext();
Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child1", "Expected child1.");
}
示例3: ZeroChildren
public void ZeroChildren ()
{
document.LoadXml ("<foo/>");
documentElement = document.DocumentElement;
Assert.AreEqual (documentElement.GetEnumerator().MoveNext(), false, "Should be empty node list.");
}
示例4: CurrentAfterLastNode
public void CurrentAfterLastNode ()
{
document.LoadXml ("<foo><child1/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
enumerator.MoveNext();
enumerator.MoveNext();
try
{
obj = enumerator.Current;
Assert.Fail ("Calling Current property after last node in list should have thrown InvalidOperationException.");
}
catch (InvalidOperationException) { }
}
示例5: CurrentDoesntMove
public void CurrentDoesntMove ()
{
document.LoadXml ("<foo><child1/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
enumerator.MoveNext();
Assert.AreEqual (Object.ReferenceEquals(enumerator.Current, enumerator.Current), true, "Consecutive calls to Current property should yield same reference.");
}
示例6: RemoveOnlyChildAffectOnEnumeration
public void RemoveOnlyChildAffectOnEnumeration ()
{
document.LoadXml ("<foo><child1/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
element.RemoveChild(element.FirstChild);
Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
}
示例7: saveTestRemoveAllAffectOnEnumeration
// TODO: Take the word save off front of this method when XmlNode.RemoveAll() is fully implemented.
public void saveTestRemoveAllAffectOnEnumeration ()
{
document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
Assert.AreEqual (element.ChildNodes.Count, 3, "Expected 3 children.");
Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
element.RemoveAll();
Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
}
示例8: saveTestReplaceChildAffectOnEnumeration
// TODO: Take the word save off front of this method when XmlNode.ReplaceChild() is implemented.
public void saveTestReplaceChildAffectOnEnumeration ()
{
document.LoadXml ("<foo><child1/><child2/></foo>");
element = document.DocumentElement;
node = document.CreateElement("child3");
enumerator = element.GetEnumerator();
Assert.AreEqual (enumerator.MoveNext(), true, "MoveNext should have succeeded.");
element.ReplaceChild(node, element.LastChild);
enumerator.MoveNext();
Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child3", "Expected child3 element.");
Assert.AreEqual (enumerator.MoveNext(), false, "MoveNext should have failed.");
}
示例9: RemoveChildAffectOnEnumerationWhenEnumeratorIsOnRemovedChild
public void RemoveChildAffectOnEnumerationWhenEnumeratorIsOnRemovedChild ()
{
document.LoadXml ("<foo><child1/><child2/><child3/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator ();
enumerator.MoveNext ();
enumerator.MoveNext ();
Assert.AreEqual ("child2", ((XmlElement)enumerator.Current).LocalName, "Expected child2 element.");
Assert.AreEqual ("child2", element.FirstChild.NextSibling.LocalName, "Expected child2 element.");
element.RemoveChild (element.FirstChild.NextSibling);
enumerator.MoveNext ();
try {
element = (XmlElement) enumerator.Current;
Assert.Fail ("Expected an InvalidOperationException.");
} catch (InvalidOperationException) { }
}
示例10: RemoveChildAffectOnEnumeration
public void RemoveChildAffectOnEnumeration ()
{
document.LoadXml ("<foo><child1/><child2/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
element.RemoveChild(element.FirstChild);
enumerator.MoveNext();
Assert.AreEqual (((XmlElement)enumerator.Current).LocalName, "child2", "Expected child2 element.");
}
示例11: CheckElementForOPCCompliance
/* OPC Compliance methods */
/**
* Check the element for the following OPC compliance rules:
* <p>
* Rule M4.2: A format consumer shall consider the use of the Markup
* Compatibility namespace to be an error.
* </p><p>
* Rule M4.3: Producers shall not create a document element that contains
* refinements to the Dublin Core elements, except for the two specified in
* the schema: <dcterms:created> and <dcterms:modified> Consumers shall
* consider a document element that violates this constraint to be an error.
* </p><p>
* Rule M4.4: Producers shall not create a document element that contains
* the xml:lang attribute. Consumers shall consider a document element that
* violates this constraint to be an error.
* </p><p>
* Rule M4.5: Producers shall not create a document element that contains
* the xsi:type attribute, except for a <dcterms:created> or
* <dcterms:modified> element where the xsi:type attribute shall be present
* and shall hold the value dcterms:W3CDTF, where dcterms is the namespace
* prefix of the Dublin Core namespace. Consumers shall consider a document
* element that violates this constraint to be an error.
* </p>
*/
public void CheckElementForOPCCompliance(XmlElement el)
{
foreach (XmlAttribute attr in el.Attributes)
{
if (attr.Name.StartsWith("xmlns:"))
{
string namespacePrefix = attr.Name.Substring(6);
if (nsmgr.LookupNamespace(namespacePrefix).Equals(PackageNamespaces.MARKUP_COMPATIBILITY))
{
// Rule M4.2
throw new InvalidFormatException(
"OPC Compliance error [M4.2]: A format consumer shall consider the use of the Markup Compatibility namespace to be an error.");
}
}
}
// Check the current element
// Rule M4.3
if (el.NamespaceURI.Equals(
namespaceDcTerms)
&& !(el.LocalName.Equals(KEYWORD_CREATED) || el.LocalName
.Equals(KEYWORD_MODIFIED)))
throw new InvalidFormatException(
"OPC Compliance error [M4.3]: Producers shall not create a document element that contains refinements to the Dublin Core elements, except for the two specified in the schema: <dcterms:created> and <dcterms:modified> Consumers shall consider a document element that violates this constraint to be an error.");
// Rule M4.4
if (el.Attributes["lang", namespaceXML] != null)
throw new InvalidFormatException(
"OPC Compliance error [M4.4]: Producers shall not create a document element that contains the xml:lang attribute. Consumers shall consider a document element that violates this constraint to be an error.");
// Rule M4.5
if (el.NamespaceURI.Equals(
namespaceDcTerms))
{
// DCTerms namespace only use with 'created' and 'modified' elements
String elName = el.LocalName;
if (!(elName.Equals(KEYWORD_CREATED) || elName
.Equals(KEYWORD_MODIFIED)))
throw new InvalidFormatException("Namespace error : " + elName
+ " shouldn't have the following naemspace -> "
+ namespaceDcTerms);
// Check for the 'xsi:type' attribute
XmlAttribute typeAtt = el.Attributes["xsi:type"];
if (typeAtt == null)
throw new InvalidFormatException("The element '" + elName
+ "' must have the '" + nsmgr.LookupPrefix(namespaceXSI)
+ ":type' attribute present !");
// Check for the attribute value => 'dcterms:W3CDTF'
if (!typeAtt.Value.Equals("dcterms:W3CDTF"))
throw new InvalidFormatException("The element '" + elName
+ "' must have the '" + nsmgr.LookupPrefix(namespaceXSI)
+ ":type' attribute with the value 'dcterms:W3CDTF' !");
}
// Check its children
IEnumerator itChildren = el.GetEnumerator();
while (itChildren.MoveNext())
{
if (itChildren.Current is XmlElement)
CheckElementForOPCCompliance((XmlElement)itChildren.Current);
}
}
示例12: CurrentBeforeFirstNode
public void CurrentBeforeFirstNode ()
{
document.LoadXml ("<foo><child1/></foo>");
element = document.DocumentElement;
enumerator = element.GetEnumerator();
try
{
obj = enumerator.Current;
Fail ("Calling Current property before first node in list should have thrown InvalidOperationException.");
} catch (InvalidOperationException) { }
}