当前位置: 首页>>代码示例>>C#>>正文


C# XmlDocument.InsertAfter方法代码示例

本文整理汇总了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;
    }
开发者ID:emcgurty,项目名称:ASP_NET_with_XML_List,代码行数:33,代码来源:GetXMLdoc.cs

示例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);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:87,代码来源:TestXmlDocument.cs


注:本文中的XmlDocument.InsertAfter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。