本文整理汇总了C#中XmlDocument.InsertAfter方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.InsertAfter方法的具体用法?C# XmlDocument.InsertAfter怎么用?C# XmlDocument.InsertAfter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.InsertAfter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenAppXMLFile
public XmlDocument OpenAppXMLFile()
{
string App_Path = @ConfigurationManager.AppSettings["Data_Path"].ToString();
App_Path = App_Path + "Items.xml";
if (File.Exists(@App_Path))
{
try
{
xmldoc = new XmlDocument();
xmldoc.Load(@App_Path);
}
catch (Exception ex)
{
/// Do not currently understand how to terminate the ThreadStart in the event of a failure
GlobalClass.ErrorMessage = "Error in AppThreads(OpenAppFile): " + ex.Message;
}
}
else
{
xmldoc = new XmlDocument();
XmlNode iheader = xmldoc.CreateXmlDeclaration("1.0", "UTF-8", null);
xmldoc.AppendChild(iheader);
XmlElement root = xmldoc.CreateElement("dataroot");
xmldoc.InsertAfter(root, iheader);
xmldoc.Save(@App_Path);
}
return xmldoc;
}
示例2: TestXmlDocumentAddXmlDeclaration
// Test adding an XML declaration to the document.
public void TestXmlDocumentAddXmlDeclaration()
{
XmlDocument doc = new XmlDocument();
// Add the declaration.
XmlDeclaration decl =
doc.CreateXmlDeclaration("1.0", null, null);
AssertNull("XmlDeclaration (1)", decl.ParentNode);
AssertEquals("XmlDeclaration (2)", doc, decl.OwnerDocument);
doc.AppendChild(decl);
AssertEquals("XmlDeclaration (3)", doc, decl.ParentNode);
AssertEquals("XmlDeclaration (4)", doc, decl.OwnerDocument);
// Try to add it again, which should fail this time.
try
{
doc.AppendChild(decl);
Fail("adding XmlDeclaration node twice");
}
catch(InvalidOperationException)
{
// Success
}
try
{
doc.PrependChild(decl);
Fail("prepending XmlDeclaration node twice");
}
catch(InvalidOperationException)
{
// Success
}
// Adding a document type before should fail.
XmlDocumentType type =
doc.CreateDocumentType("foo", null, null, null);
try
{
doc.PrependChild(type);
Fail("prepending XmlDocumentType");
}
catch(InvalidOperationException)
{
// Success
}
// Adding a document type after should succeed.
doc.AppendChild(type);
// Adding an element before should fail.
XmlElement element = doc.CreateElement("foo");
try
{
doc.PrependChild(element);
Fail("prepending XmlElement");
}
catch(InvalidOperationException)
{
// Success
}
// Adding the element between decl and type should fail.
try
{
doc.InsertAfter(element, decl);
Fail("inserting XmlElement between XmlDeclaration " +
"and XmlDocumentType");
}
catch(InvalidOperationException)
{
// Success
}
try
{
doc.InsertBefore(element, type);
Fail("inserting XmlElement between XmlDeclaration " +
"and XmlDocumentType (2)");
}
catch(InvalidOperationException)
{
// Success
}
// Adding an element after should succeed.
doc.AppendChild(element);
}