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


C# XmlDocument.InsertBefore方法代码示例

本文整理汇总了C#中System.Xml.XmlDocument.InsertBefore方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.InsertBefore方法的具体用法?C# XmlDocument.InsertBefore怎么用?C# XmlDocument.InsertBefore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.InsertBefore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateTestDoc

        private XmlDocument CreateTestDoc()
        {
            XmlDocument doc = new XmlDocument();

            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);

            doc.InsertBefore(xmlDeclaration, doc.DocumentElement);

            // it is necessary to have this root node without attributes, to comply with the xml documents generated by TYML2XML
            XmlElement rootNode = doc.CreateElement(TYml2Xml.ROOTNODEINTERNAL);
            doc.AppendChild(rootNode);

            XmlElement childNode = doc.CreateElement(TYml2Xml.XMLELEMENT);
            childNode.SetAttribute("name", "testname");
            childNode.SetAttribute("active", true.ToString());
            rootNode.AppendChild(childNode);

            XmlElement anotherChildNode = doc.CreateElement(TYml2Xml.XMLELEMENT);
            anotherChildNode.SetAttribute("name", "testname2");
            anotherChildNode.SetAttribute("active", true.ToString());
            rootNode.AppendChild(anotherChildNode);

            XmlElement grandChildNode = doc.CreateElement(TYml2Xml.XMLELEMENT);
            grandChildNode.SetAttribute("name", "grandchild1");
            grandChildNode.SetAttribute("active", true.ToString());
            childNode.AppendChild(grandChildNode);

            XmlElement grandChild2Node = doc.CreateElement(TYml2Xml.XMLELEMENT);
            grandChild2Node.SetAttribute("name", "grandchild2");
            grandChild2Node.SetAttribute("active", false.ToString());
            childNode.AppendChild(grandChild2Node);

            return doc;
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:34,代码来源:test.cs

示例2: GenerateAllLocationsReport

        public void GenerateAllLocationsReport(IEnumerable<LocationReport> locationReports)
        {
            var report = new XmlDocument();
            var xmlDeclaration = report.CreateXmlDeclaration("1.0", "UTF-8", null);
            var root = report.CreateElement("sales");
            report.AppendChild(root);
            report.InsertBefore(xmlDeclaration, root);

            foreach (var locationReport in locationReports)
            {
                var sale = report.CreateElement("location");
                sale.SetAttribute("name", locationReport.LocationName);
                root.AppendChild(sale);
                foreach (var entry in locationReport.Entries)
                {
                    var summary = report.CreateElement("summary");
                    summary.SetAttribute("date", entry.Date.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture));
                    summary.SetAttribute("total-sum", entry.TotalSum.ToString(CultureInfo.InvariantCulture));
                    sale.AppendChild(summary);
                }
            }

            if (!Directory.Exists(XmlSettings.Default.ReportDestinationFolderLocation))
            {
                Directory.CreateDirectory(XmlSettings.Default.ReportDestinationFolderLocation);
            }

            report.Save(
                XmlSettings.Default.ReportDestinationFolderLocation + XmlSettings.Default.ReportDestionationFileName);
        }
开发者ID:Team-Tower-Databases-Online,项目名称:Databases-Teamwork-2015,代码行数:30,代码来源:XmlData.cs

示例3: Main

        static void Main()
        {
            XmlDocument doc = new XmlDocument();
            XmlDocument outputDoc = new XmlDocument();
            doc.Load("../../../catalog.xml");

            Console.WriteLine("Loaded XML document:");

            XmlNode Root = doc.DocumentElement;

            XmlDeclaration xmlDeclaration = outputDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement root = outputDoc.DocumentElement;
            outputDoc.InsertBefore(xmlDeclaration, root);

            XmlElement element1 = outputDoc.CreateElement(string.Empty, "albums", string.Empty);
            outputDoc.AppendChild(element1);

            foreach (XmlNode album in Root.ChildNodes)
            {
                if (int.Parse(album.ChildNodes[3].Attributes["value"].Value) > 20)
                {
                    XmlNode oNode = outputDoc.ImportNode(album, true);
                    outputDoc.DocumentElement.AppendChild(oNode);

                }
            }
            outputDoc.Save("../../../document.xml");
        }
开发者ID:uFreezy,项目名称:SoftUni-Database-Applications,代码行数:28,代码来源:Program.cs

示例4: SaveToXmlFile

        //////////////////////////////////////////////////////////////////////////
        public bool SaveToXmlFile(string Filename)
        {
            try
            {
                XmlDocument Doc = new XmlDocument();

                // header
                XmlDeclaration Decl = Doc.CreateXmlDeclaration("1.0", "utf-8", null);

                Assembly A = Assembly.GetExecutingAssembly();
                XmlComment Comment1 = Doc.CreateComment("Generated by: " + A.GetName());
                XmlComment Comment2 = Doc.CreateComment("Generated on: " + DateTime.Now.ToString());

                // root
                XmlNode RootNode = SaveToXmlNode(Doc);
                Doc.InsertBefore(Decl, Doc.DocumentElement);
                Doc.AppendChild(Comment1);
                Doc.AppendChild(Comment2);
                Doc.AppendChild(RootNode);

                // save to file
                XmlTextWriter Writer = new XmlTextWriter(Filename, null);
                Writer.Formatting = Formatting.Indented;
                Doc.Save(Writer);
                Writer.Close();

                return true;
            }
            catch
            {
                return false;
            }
        }
开发者ID:segafan,项目名称:wme1_jankavan_tlc_edition-repo,代码行数:34,代码来源:SettingsMgr.cs

示例5: GenerateXMLPayload

        // This function generates the XML request body
        // for the FolderSync request.
        protected override void GenerateXMLPayload()
        {
            // If WBXML was explicitly set, use that
            if (WbxmlBytes != null)
                return;

            // Otherwise, use the properties to build the XML and then WBXML encode it
            XmlDocument folderSyncXML = new XmlDocument();

            XmlDeclaration xmlDeclaration = folderSyncXML.CreateXmlDeclaration("1.0", "utf-8", null);
            folderSyncXML.InsertBefore(xmlDeclaration, null);

            XmlNode folderSyncNode = folderSyncXML.CreateElement(Xmlns.folderHierarchyXmlns, "FolderSync", Namespaces.folderHierarchyNamespace);
            folderSyncNode.Prefix = Xmlns.folderHierarchyXmlns;
            folderSyncXML.AppendChild(folderSyncNode);

            if (syncKey == "")
                syncKey = "0";

            XmlNode syncKeyNode = folderSyncXML.CreateElement(Xmlns.folderHierarchyXmlns, "SyncKey", Namespaces.folderHierarchyNamespace);
            syncKeyNode.Prefix = Xmlns.folderHierarchyXmlns;
            syncKeyNode.InnerText = syncKey;
            folderSyncNode.AppendChild(syncKeyNode);

            StringWriter sw = new StringWriter();
            XmlTextWriter xmlw = new XmlTextWriter(sw);
            xmlw.Formatting = Formatting.Indented;
            folderSyncXML.WriteTo(xmlw);
            xmlw.Flush();

            XmlString = sw.ToString();
        }
开发者ID:MishaKharaba,项目名称:ExchangeActiveSync,代码行数:34,代码来源:ASFolderSyncRequest.cs

示例6: GenerateSalesReport

        public void GenerateSalesReport(string fileName = DefaultSaleReportFileName)
        {
            XmlDocument report = new XmlDocument();
            XmlDeclaration xmlDeclaration = report.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement root = report.CreateElement("sales");
            report.AppendChild(root);
            report.InsertBefore(xmlDeclaration, root);
            using (var db = new CarPartsDbContext())
            {
                var groupedSales = db.Sales.GroupBy(s => s.Vendor)
                                        .ToList();

                foreach (var group in groupedSales)
                {
                    XmlElement sale = report.CreateElement("sale");
                    sale.SetAttribute("vendor", group.Key.Name);
                    root.AppendChild(sale);
                    foreach (var s in group)
                    {
                        XmlElement summary = report.CreateElement("summary");
                        summary.SetAttribute("date", s.Date.ToString("dd-MMM-yyyy", CultureInfo.InvariantCulture));
                        summary.SetAttribute("total-sum", (s.UnitPrice * s.Quantity).ToString());
                        sale.AppendChild(summary);
                    }
                }
            }

            if (!Directory.Exists(this.reportsDestinationPath))
            {
                Directory.CreateDirectory(this.reportsDestinationPath);
            }

            report.Save(this.reportsDestinationPath + fileName);
        }
开发者ID:TA-2015-Databases-Team-Xenon,项目名称:CarParts,代码行数:34,代码来源:XmlHandler.cs

示例7: SetXmLsitemap

        /// <summary>
        /// 
        /// </summary>
        /// <param name="items"></param>
        /// <param name="command"></param>
        /// <param name="schedule"></param>
        public void SetXmLsitemap(Item[] items, CommandItem command, ScheduleItem schedule)
        {
            if (ConfigurationHelper.IsAuthoringServer())
            {
                try
                {
                    XmlDocument xmlDoc = new XmlDocument();
                    XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);

                    XmlElement rootNode = xmlDoc.CreateElement("urlset");
                    rootNode.SetAttribute("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9");
                    xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
                    xmlDoc.AppendChild(rootNode);

                    //we will take only approved items / pages
                    string databaseName = "web";
                    string startItemPath = ConfigurationHelper.GetSitecoreSetting("rootPath");
                    Database database = Factory.GetDatabase(databaseName);
                    UrlOptions urlOptions = UrlOptions.DefaultOptions;
                    urlOptions.AlwaysIncludeServerUrl = false;

                    Item item = database.GetItem(startItemPath);
                    AddUrlEntry(item, xmlDoc, rootNode, urlOptions);
                    xmlDoc.Save(System.Web.Hosting.HostingEnvironment.MapPath("/sitemap.xml"));
                }
                catch (Exception ex)
                {
                    Log.Error("Error at sitemap xml handler.", ex, this);
                }
            }
        }
开发者ID:thwittek,项目名称:Sitecore-XML-Sitemap,代码行数:37,代码来源:ScheduleContainer.cs

示例8: CreateXmlDocument

		public static XmlDocument CreateXmlDocument()
		{
			XmlDocument doc = new XmlDocument();
			XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "utf-8", "");
			doc.InsertBefore(decl, doc.DocumentElement);
			return doc;
		}
开发者ID:icegithub,项目名称:csharp-exercise,代码行数:7,代码来源:XmlHelper.cs

示例9: GerarConfiguracao

        public static void GerarConfiguracao(string Servidor, string BD)
        {
            // Pasta aonde está o arquivo + nome do arquivo a ser gerado.
            string arquivo = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase) + Path.DirectorySeparatorChar + "conexao.xml";

            // Criação do Xml com os dados
            XmlDocument xml = new XmlDocument();
            XmlDeclaration declaracaoXml = xml.CreateXmlDeclaration("1.0", "utf-8", null);
            XmlElement noRaiz = xml.CreateElement("Configuracao");
            xml.InsertBefore(declaracaoXml, xml.DocumentElement);
            xml.AppendChild(noRaiz);

            XmlElement noPai = xml.CreateElement("Servidor");
            xml.DocumentElement.PrependChild(noPai);

            XmlElement endereco= xml.CreateElement("Endereco");
            XmlElement database  = xml.CreateElement("Database");

            // Inserir Texto
            XmlText enderecoText = xml.CreateTextNode(Servidor);
            XmlText databaseText= xml.CreateTextNode(BD);

            // append the nodes to the parentNode without the value
            noPai.AppendChild(endereco);
            noPai.AppendChild(database);

            // save the value of the fields into the nodes
            endereco.AppendChild(enderecoText);
            database.AppendChild(databaseText);

            // Save to the XML file
            xml.Save(arquivo.Substring(6,arquivo.Length - 6));
        }
开发者ID:rafaellrochaa,项目名称:FormataLayoutExcel,代码行数:33,代码来源:Configuracao.cs

示例10: GetCapabilities

        /// <summary>
        /// Generates a capabilities file from a map object for use in WMS services
        /// </summary>
        /// <remarks>The capabilities document uses the v1.3.0 OpenGIS WMS specification</remarks>
        /// <param name="map">The map to create capabilities for</param>
        /// <param name="description">Additional description of WMS</param>
        /// <param name="request">An abstraction of the <see cref="HttpContext"/> request</param>
        /// <returns>Returns XmlDocument describing capabilities</returns>
        public static XmlDocument GetCapabilities(Map map, WmsServiceDescription description, IContextRequest request)
        {
            XmlDocument capabilities = new XmlDocument();

            // Insert XML tag
            capabilities.InsertBefore(capabilities.CreateXmlDeclaration("1.0", "UTF-8", String.Empty), capabilities.DocumentElement);
            string format = String.Format("Capabilities generated by SharpMap v. {0}", Assembly.GetExecutingAssembly().GetName().Version);
            capabilities.AppendChild(capabilities.CreateComment(format));

            // Create root node
            XmlNode rootNode = capabilities.CreateNode(XmlNodeType.Element, "WMS_Capabilities", WmsNamespaceUri);
            rootNode.Attributes.Append(CreateAttribute("version", "1.3.0", capabilities));

            XmlAttribute attr = capabilities.CreateAttribute("xmlns", "xsi", "http://www.w3.org/2000/xmlns/");
            attr.InnerText = "http://www.w3.org/2001/XMLSchema-instance";
            rootNode.Attributes.Append(attr);

            rootNode.Attributes.Append(CreateAttribute("xmlns:xlink", XlinkNamespaceUri, capabilities));
            XmlAttribute attr2 = capabilities.CreateAttribute("xsi", "schemaLocation",
                                                              "http://www.w3.org/2001/XMLSchema-instance");
            attr2.InnerText = "http://schemas.opengis.net/wms/1.3.0/capabilities_1_3_0.xsd";
            rootNode.Attributes.Append(attr2);

            // Build Service node
            rootNode.AppendChild(GenerateServiceNode(ref description, capabilities));

            // Build Capability node
            XmlNode capabilityNode = GenerateCapabilityNode(map, capabilities, description.PublicAccessURL, request);
            rootNode.AppendChild(capabilityNode);

            capabilities.AppendChild(rootNode);

            //TODO: Validate output against schema
            return capabilities;
        }
开发者ID:geobabbler,项目名称:SharpMap,代码行数:43,代码来源:ServerCapabilities.cs

示例11: Xml

        public XmlDocument Xml()
        {
            if (_manifestXml != null)
                return _manifestXml;

            _manifestXml = new XmlDocument {PreserveWhitespace = true};
            var xmlDeclaration = _manifestXml.CreateXmlDeclaration("1.0", "UTF-8", null);
            _manifestXml.AppendChild(_manifestXml.CreateElement("manifest", NavneromUtility.DifiSdpSchema10));
            _manifestXml.InsertBefore(xmlDeclaration, _manifestXml.DocumentElement);

            if (Forsendelse.Sendes(Postmetode.Digital))
            {
                _manifestXml.DocumentElement.AppendChild(MottakerNode());
            }

            _manifestXml.DocumentElement.AppendChild(AvsenderNode());

            var hoveddokument = Forsendelse.Dokumentpakke.Hoveddokument;
            _manifestXml.DocumentElement.AppendChild(DokumentNode(hoveddokument, "hoveddokument", hoveddokument.Tittel));

            foreach (var vedlegg in Forsendelse.Dokumentpakke.Vedlegg)
            {
                _manifestXml.DocumentElement.AppendChild(DokumentNode(vedlegg, "vedlegg", vedlegg.Tittel));
            }

            return _manifestXml;
        }
开发者ID:difi,项目名称:sikker-digital-post-klient-dotnet,代码行数:27,代码来源:Manifest.cs

示例12: CreateNewLodgeXmlFile

 public static string CreateNewLodgeXmlFile(string xmlFileName)
 {
     string success = "ono";
     try
     {
         XmlDocument xdoc = new XmlDocument();
         XmlDeclaration xmlDeclaration = xdoc.CreateXmlDeclaration("1.0", "utf-8", null);
         xdoc.InsertBefore(xmlDeclaration, xdoc.DocumentElement);
         var root = xdoc.CreateElement("Lodge");
         xdoc.AppendChild(root);
         root.AppendChild(xdoc.CreateElement("Members"));
         root.AppendChild(xdoc.CreateElement("CalendarEvents"));
         root.AppendChild(xdoc.CreateElement("Committees"));
         root.AppendChild(xdoc.CreateElement("Officers"));
         root.AppendChild(xdoc.CreateElement("Minutes"));
         root.AppendChild(xdoc.CreateElement("Inventory"));
         root.AppendChild(xdoc.CreateElement("Cash"));
         root.AppendChild(xdoc.CreateElement("People"));
         root.AppendChild(xdoc.CreateElement("Refs"));
         //AddDefaulRefs(xdoc);
         xdoc.Save(xmlFileName);
         ResetDefaults(xmlFileName);
         success = "ok";
     }
     catch (Exception ex)
     {
         success = ex.Message;
     }
     return success;
 }
开发者ID:CurtisRhodes,项目名称:LodgeSecretary,代码行数:30,代码来源:LodgeDataXml.cs

示例13: AppendDecleration

 private static XmlDeclaration AppendDecleration(XmlDocument xmlDoc)
 {
     // Write down the XML declaration
     XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", null);
     xmlDoc.InsertBefore(xmlDeclaration, xmlDoc.DocumentElement);
     return xmlDeclaration;
 }
开发者ID:cityindex-attic,项目名称:crap4net,代码行数:7,代码来源:XmlFormatter.cs

示例14: CreatePackagesDotConfigFile

        public System.Xml.XmlDocument CreatePackagesDotConfigFile(IEnumerable<Models.NugetPackageInfo> packages)
        {
            XmlDocument doc = new XmlDocument();

            XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            XmlElement root = doc.DocumentElement;
            doc.InsertBefore(xmlDeclaration, root);

            XmlElement packagesElement = doc.CreateElement(string.Empty, "packages", string.Empty);
            doc.AppendChild(packagesElement);

            foreach (NugetPackageInfo package in packages)
            {
                XmlElement packageElement = doc.CreateElement(string.Empty, "package", string.Empty);
                packagesElement.AppendChild(packageElement);

                XmlAttribute idAttribute = doc.CreateAttribute("id");
                idAttribute.Value = package.Info.Name;
                packageElement.Attributes.Append(idAttribute);

                XmlAttribute versionAttribute = doc.CreateAttribute("version");
                versionAttribute.Value = package.Info.VersionNumber.ToString();
                packageElement.Attributes.Append(versionAttribute);

                XmlAttribute frameworkAttribute = doc.CreateAttribute("targetFramework");
                frameworkAttribute.Value = "net45";
                packageElement.Attributes.Append(frameworkAttribute);
            }

            return doc;
        }
开发者ID:SaintSkeeta,项目名称:Sitecore-Nuget-Package-Discoverer,代码行数:31,代码来源:ResultsFormatter.cs

示例15: _processDocument

        private static void _processDocument(XmlNode document, StreamWriter sw)
        {
            XmlDocument docNode = new XmlDocument();
            XmlDeclaration xmlDeclaration = docNode.CreateXmlDeclaration("1.0", "cp866", null);
            docNode.InsertBefore(xmlDeclaration, docNode.DocumentElement);

            XmlElement docRoot = (XmlElement)docNode.ImportNode(document, true);
            docNode.AppendChild(docRoot);

            Regex rgx = new Regex("<(\\w+)>");

            String s = rgx.Replace(docNode.OuterXml, "<$1 xmlns=\"itek\">");
            s = s.Replace("<Документ xmlns=\"itek\">", "<Документ>");
            s = s.Replace("РаботыЧужие", "true");

            eurocarService.Документ documentRequest = (eurocarService.Документ)_x.Deserialize(new System.IO.StringReader(s));

            try
            {
                sw.WriteLine(DateTime.Now.ToString() + " Отправка документа " + documentRequest.Номер);
                _cl.PutDoc(documentRequest);
            }
            catch (ProtocolException e)
            {
                // Silently except it...
            }
        }
开发者ID:eur00t,项目名称:atlant.xml2SOAP,代码行数:27,代码来源:FilesProcessor.cs


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