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


C# XmlDocument.PrependChild方法代码示例

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


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

示例1: CreateXML

        public static void CreateXML()
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration xmlDeclar = doc.CreateXmlDeclaration(version:"1.0",standalone:"yes",encoding:"");
            doc.PrependChild(xmlDeclar);
            XmlElement element = doc.CreateElement(name: "Users");
            doc.AppendChild(element);
            XmlElement user = doc.CreateElement(name: "User");

            user.SetAttribute(name: "ID", value: "1");
            element.AppendChild(newChild: user);
            XmlElement userage = doc.CreateElement(name: "Age");
            element.FirstChild.AppendChild(userage);
            XmlElement userName = doc.CreateElement(name: "Name");
            userName.InnerText = "jambor";
            element.FirstChild.PrependChild(newChild: userName);
            XmlElement userPhone= doc.CreateElement(name: "Phone");
            XmlNode xmlNode = doc.DocumentElement;
            element.FirstChild.InsertBefore(newChild: userPhone, refChild: xmlNode.FirstChild.FirstChild);
            //XmlElement userAdd = doc.CreateElement(name: "Address");

            //xmlNode.InsertAfter(newChild: userPhone, refChild: xmlNode.SelectNodes(xpath:"Name")[0]);

            doc.Save(filename: @"d:\user.xml");
        }
开发者ID:JamborYao,项目名称:basic,代码行数:25,代码来源:Program.cs

示例2: XslExportTransform

		public static XmlDocument XslExportTransform (XmlDocument doc)
		{
			XmlReader reader = Registry.GladeExportXsl.Transform (doc, null, (XmlResolver)null);
			doc = new XmlDocument ();
			doc.PreserveWhitespace = true;
			doc.Load (reader);

			XmlDocumentType doctype = doc.CreateDocumentType ("glade-interface", null, Glade20SystemId, null);
			doc.PrependChild (doctype);

			return doc;
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:12,代码来源:GladeUtils.cs

示例3: XslExportTransform

		public static XmlDocument XslExportTransform (XmlDocument doc)
		{
			StringWriter sw = new StringWriter ();
			XmlWriter xw = XmlWriter.Create (sw);
			Registry.GladeExportXsl.Transform (doc, xw);
			XmlReader reader = XmlReader.Create (sw.ToString ());
			doc = new XmlDocument ();
			doc.PreserveWhitespace = true;
			doc.Load (reader);

			XmlDocumentType doctype = doc.CreateDocumentType ("glade-interface", null, Glade20SystemId, null);
			doc.PrependChild (doctype);

			return doc;
		}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:15,代码来源:GladeUtils.cs

示例4: Serialize

        public XmlDocument Serialize(DataTable table)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }

            if (table.Columns.Count == 0)
            {
                throw new ArgumentOutOfRangeException("table", "DataTable specified contains no columns");
            }

            var doc = new XmlDocument();
            var xmlDeclaration = doc.CreateXmlDeclaration("1.0", "utf-8", null);

            doc.PrependChild(xmlDeclaration);

            var root = doc.CreateElement(ColumnCollectionElementName);
            doc.AppendChild(root);

            foreach (var dataCol in table.Columns)
            {
                var col = (DataColumn)dataCol;
                var el = doc.CreateElement(ColumnElementName);

                el.SetAttribute(AttributeNames.Name, col.ColumnName);
                el.SetAttribute(AttributeNames.Type, col.DataType.FullName);
                el.SetAttribute(AttributeNames.Nullable, col.AllowDBNull.ToString(CultureInfo.InvariantCulture));

                // MaxLength only relevant for strings
                if (col.DataType == typeof(string))
                {
                    el.SetAttribute(AttributeNames.Length, col.MaxLength.ToString(CultureInfo.InvariantCulture));
                }

                root.AppendChild(el);
            }

            return doc;
        }
开发者ID:veraveramanolo,项目名称:power-show,代码行数:40,代码来源:DataTableStructureSerializer.cs

示例5: getKmlDocument

        /// <summary>
        /// return a KML document
        /// </summary>
        /// <returns></returns>
        private XmlDocument getKmlDocument()
        {
            // Create the document.
            XmlDocument doc = new XmlDocument();

            // Insert the xml processing instruction and the root node
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null);
            doc.PrependChild(dec);

            XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System KML interface");
            doc.AppendChild(commentnode);

            XmlElement nodeKml = doc.CreateElement("kml");
            nodeKml.SetAttribute("xmlns", "http://earth.google.com/kml/2.1");
            doc.AppendChild(nodeKml);

            XmlElement elem = getXml(doc);
            nodeKml.AppendChild(elem);

            return (doc);
        }
开发者ID:kasertim,项目名称:sentience,代码行数:25,代码来源:kml.cs

示例6: ToXml

        /// <summary>
        /// Return a string containing the metadata XML based on the settings added to this instance.
        /// The resulting XML will be signed, if the AsymmetricAlgoritm property has been set.
        /// </summary>
        public string ToXml(Encoding enc)
        {
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true;

            doc.LoadXml( Serialization.SerializeToXmlString(_entity));

            // Add the correct encoding to the head element.
            if (doc.FirstChild is XmlDeclaration)
                ((XmlDeclaration) doc.FirstChild).Encoding = enc.WebName;
            else
                doc.PrependChild(doc.CreateXmlDeclaration("1.0", enc.WebName, null));

            if (Sign)
                SignDocument(doc);

            return doc.OuterXml;
        }
开发者ID:kiniry-supervision,项目名称:OpenNemID,代码行数:22,代码来源:Saml20MetadataDocument.cs

示例7: Serialize

        // ---------------------------------------------------------------------------------------------------
        // Serialize
        //
        // Param assemblyPath: The full path + name of the assembly to be serialized
        // ---------------------------------------------------------------------------------------------------
        public static string Serialize(string assemblyPath)
        {
            Assembly assembly;

            // load the assembly
            try {
                //assembly = Assembly.ReflectionOnlyLoadFrom(assemblyPath);
                assembly = Assembly.LoadFrom(assemblyPath);
            }
            catch (Exception exc) {
                throw exc;
            }

            // extract the assembly name which is used as the XML parent node
            string sAssemblyName = assembly.FullName.Split(',')[0];

            // create a new XML Document
            XmlDocument xmlDoc = new XmlDocument();

            XmlNamespaceManager ns = new XmlNamespaceManager(xmlDoc.NameTable);
            ns.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata");
            ns.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");

            XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", String.Empty);
            xmlDoc.PrependChild(xmlDec);

            // create parent node
            System.Xml.XmlElement elemRoot = xmlDoc.CreateElement(sAssemblyName);
            xmlDoc.AppendChild(elemRoot);

            // create longer static XML node using a string
            string sSchemaNode = "<xs:schema id=\"" + sAssemblyName + "\" xmlns=\"\" ";
                sSchemaNode += "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" ";
                sSchemaNode += "xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">";
                sSchemaNode += "<xs:element name=\"" + sAssemblyName + "\" msdata:IsDataSet=\"true\" msdata:Locale=\"en-US\">";
                sSchemaNode += "<xs:complexType><xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\">";
                sSchemaNode += "</xs:choice></xs:complexType></xs:element></xs:schema>";

            XmlDocumentFragment xmlDocFragment = xmlDoc.CreateDocumentFragment();
            xmlDocFragment.InnerXml = sSchemaNode;
            elemRoot.AppendChild(xmlDocFragment);

            // select the "choice" node to include member types
            XmlNode choiceNode = xmlDoc.SelectSingleNode("/descendant::xs:choice[1]", ns);

            // list of all assembly types and relations
            Type[] assemblyTypes = assembly.GetTypes();

            // remove duplicates
            assemblyTypes = assemblyTypes.GroupBy(x => x.Name).Select(y => y.First()).ToArray();

            List<System.Xml.XmlElement> listAnnotations = new List<System.Xml.XmlElement>();
            
            // loop through all classes in assembly
            foreach (Type type in assemblyTypes)
            {
                List<string> listMemberNames = new List<string>();

                if (ContainsSpecialCharacters(type.Name))
                    continue;

                // create XML entries for the classes
                System.Xml.XmlElement typeElement = 
                    xmlDoc.CreateElement("xs", "element", "http://www.w3.org/2001/XMLSchema");
                typeElement.SetAttribute("name", type.Name);
                choiceNode.AppendChild(typeElement);

                System.Xml.XmlElement complexTypeElement = 
                    xmlDoc.CreateElement("xs", "complexType", "http://www.w3.org/2001/XMLSchema");
                typeElement.AppendChild(complexTypeElement);

                System.Xml.XmlElement sequenceElement = 
                    xmlDoc.CreateElement("xs", "sequence", "http://www.w3.org/2001/XMLSchema");
                complexTypeElement.AppendChild(sequenceElement);

                // loop through all properties and create XML nodes for return types
                foreach (PropertyInfo property in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
                {
                    if (ContainsSpecialCharacters(property.Name) |
                        listMemberNames.Contains(property.Name) |
                        property.GetMethod == null)
                        continue;

                    if (assemblyTypes.Contains(property.GetMethod.ReturnType))
                    {
                        System.Xml.XmlElement newAnnotationElement = 
                            CreateAnnotationElement(xmlDoc, type.Name, property.GetMethod.ReturnType.Name);
                        if (newAnnotationElement != null)
                            listAnnotations.Add(newAnnotationElement);
                    }

                    // add the member information as XML element
                    sequenceElement.AppendChild(CreateMemberElement(xmlDoc, property.Name, property.GetMethod.ReturnType));
                    listMemberNames.Add(property.Name);
                }
//.........这里部分代码省略.........
开发者ID:TextControl,项目名称:TextControl.MailMerge.DocumentServer.AssemblySerializer,代码行数:101,代码来源:AssemblySerializer.cs

示例8: ParseOptionsControls

 private string ParseOptionsControls()
 {
     XmlDocument xDoc = new XmlDocument();
     XmlElement options = xDoc.CreateElement("options");
     xDoc.AppendChild(options);
     XmlElement settings = xDoc.CreateElement("settings");
     options.AppendChild(settings);
     foreach (TreeNode tn in topLevel.Nodes)
     {
         if (tn.Tag != null && typeof(TableLayoutPanel).IsInstanceOfType(tn.Tag))
         {
             XmlElement panel = xDoc.CreateElement("panel");
             panel.SetAttribute("name", tn.Text);
             settings.AppendChild(panel);
             XmlElement controls = xDoc.CreateElement("controls");
             panel.AppendChild(controls);
             foreach (Control c in ((TableLayoutPanel)tn.Tag).Controls)
             {
                 if (!typeof(Label).IsInstanceOfType(c))
                 {
                     int firstPos = c.ToString().IndexOf(',');
                     int lastPos = c.ToString().Substring(0, firstPos).LastIndexOf('.');
                     string ctrlType = c.ToString().Substring(0, firstPos).Substring(lastPos + 1).Trim();
                     string ctrlValue = string.Empty;
                     if (ctrlType.ToLower().Equals("textbox"))
                     {
                         ctrlValue = "Text: " + c.Text;
                     }
                     else
                     {
                         ctrlValue = c.ToString().Substring(firstPos + 1).Trim();
                     }
                     XmlElement ctrl = xDoc.CreateElement("control");
                     ctrl.SetAttribute("name", c.Name);
                     ctrl.SetAttribute("type", ctrlType);
                     ctrl.InnerText = ctrlValue;
                     controls.AppendChild(ctrl);
                 }
             }
         }
     }
     XmlDeclaration declare = xDoc.CreateXmlDeclaration("1.0", "UTF-8", "yes");
     xDoc.PrependChild(declare);
     _values = xDoc.OuterXml;
     return _values;
 }
开发者ID:ViniciusConsultor,项目名称:sqlschematool,代码行数:46,代码来源:OptionsDialog.cs

示例9: XmlFromDataTable

        static public void XmlFromDataTable(System.Data.DataTable dt, 
                                                                      string file,
                                                                      string senderID)
        {
            XmlDocument doc = new XmlDocument();
            doc.PrependChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));
            XmlElement element = doc.CreateElement("Data");
            element.SetAttribute("reportDate", DateTime.Now.ToString("MM/dd/yy HH:mm"));
            element.SetAttribute("senderID", senderID);
            doc.AppendChild(element);

            XmlElement devices = doc.CreateElement("Devices");
            element.AppendChild(devices);

            foreach (DataRow r in dt.Rows)
            {
                XmlElement device = doc.CreateElement("Device");

                // add each row's cell data...
                foreach (DataColumn c in dt.Columns)
                {
                   insertElement(doc, device, c.ColumnName.Trim(), r[c.ColumnName].ToString().Trim());
                 }
                devices.AppendChild(device);
            }
            doc.Save(file);
        }
开发者ID:wra222,项目名称:testgit,代码行数:27,代码来源:GenExcelFile.cs

示例10: InspectDocument

        /// <summary>
        /// Inspect an XML document.
        /// </summary>
        /// <param name="doc">The XML document to inspect.</param>
        private void InspectDocument(XmlDocument doc)
        {
            // inspect the declaration
            if (XmlNodeType.XmlDeclaration == doc.FirstChild.NodeType)
            {
                XmlDeclaration declaration = (XmlDeclaration)doc.FirstChild;

                if (!String.Equals("utf-8", declaration.Encoding, StringComparison.OrdinalIgnoreCase))
                {
                    if (this.OnError(InspectorTestType.DeclarationEncodingWrong, declaration, "The XML declaration encoding is not properly set to 'utf-8'."))
                    {
                        declaration.Encoding = "utf-8";
                    }
                }
            }
            else // missing declaration
            {
                if (this.OnError(InspectorTestType.DeclarationMissing, null, "This file is missing an XML declaration on the first line."))
                {
                    doc.PrependChild(doc.CreateXmlDeclaration("1.0", "utf-8", null));
                }
            }

            // start inspecting the nodes at the document element
            this.InspectNode(doc.DocumentElement, 0);
        }
开发者ID:Jeremiahf,项目名称:wix3,代码行数:30,代码来源:Inspector.cs

示例11: getXmlDocument

        /// <summary>
        /// return an Xml document containing metagridBuffer
        /// </summary>
        /// <returns></returns>
        private XmlDocument getXmlDocument()
        {
            // Create the document.
            XmlDocument doc = new XmlDocument();

            // Insert the xml processing instruction and the root node
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null);
            doc.PrependChild(dec);

            XmlElement nodeGeom = doc.CreateElement("OccupancyGrids");
            doc.AppendChild(nodeGeom);
			
            nodeGeom.AppendChild(
			    getXml(doc, nodeGeom));

            return (doc);
        }
开发者ID:kasertim,项目名称:sentience,代码行数:21,代码来源:metagridBuffer.cs

示例12: GetDeviceStatus

        /// <summary>
        /// return an Xml document containing the status of the given list of devices
        /// </summary>
        /// <returns></returns>
        protected static XmlDocument GetDeviceStatus(
            ArrayList devs, 
            string status_type)
        {
            XmlDocument doc = new XmlDocument();

            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", XML_ENCODING, null);
            doc.PrependChild(dec);

            XmlElement statusreply = doc.CreateElement(status_type);
            doc.AppendChild(statusreply);

            for (int i = 0; i < devs.Count; i += 2)
            {
                string Id = (string)devs[i];
                List<string> required_properties = (List<string>)devs[i + 1];
                XmlElement status = GetDeviceStatus(Id, doc, statusreply, required_properties);
                if (status != null) statusreply.AppendChild(status);
            }

            //doc.Save("DeviceStatus.xml");

            return (doc);
        }
开发者ID:kasertim,项目名称:sentience,代码行数:28,代码来源:dpslamServer.cs

示例13: ConstructXMLRequest

        private static XmlDocument ConstructXMLRequest(BaseRequest request, RequestTypeEnum requestType)
        {
            var xmlDoc = new XmlDocument();
            try
            {

                xmlDoc.LoadXml("<Request xmlns=\"urn:sbx:apis:SbxBaseComponents\"><RequesterCredentials><ApiUserToken>"
                            + request.ApiUserToken + "</ApiUserToken><SbxUserToken>" + request.SbxUserToken +
                            "</SbxUserToken></RequesterCredentials></Request>");
                xmlDoc.PrependChild(xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null));

                var xmlRequestNode = xmlDoc.GetElementsByTagName("Request").Item(0);

                var xmlGetRequestTypeCallNode = xmlDoc.CreateElement(requestType.ToString());
                xmlGetRequestTypeCallNode.SetAttribute("xmlns", "urn:sbx:apis:SbxBaseComponents");
                xmlRequestNode.AppendChild(xmlGetRequestTypeCallNode);

                ConstructXMLCallNode(xmlDoc, request, requestType, xmlGetRequestTypeCallNode);
            }
            catch
            {
                throw new Exception("Error in Service.");
            }

            return xmlDoc;
        }
开发者ID:pass123pana,项目名称:ShoeboxedCSharpAPI,代码行数:26,代码来源:ShoeboxedService.cs

示例14: getXmlDocument

        /// <summary>
        /// return an Xml document containing camera calibration parameters
        /// </summary>
        /// <param name="device_name"></param>
        /// <param name="part_number"></param>
        /// <param name="serial_number"></param>
        /// <param name="focal_length_pixels"></param>
        /// <param name="focal_length_mm"></param>
        /// <param name="baseline_mm"></param>
        /// <param name="fov_degrees"></param>
        /// <param name="image_width"></param>
        /// <param name="image_height"></param>
        /// <param name="lens_distortion_curve"></param>
        /// <param name="centre_of_distortion_x"></param>
        /// <param name="centre_of_distortion_y"></param>
        /// <param name="minimum_rms_error"></param>
        /// <param name="rotation"></param>
        /// <param name="scale"></param>
        /// <param name="offset_x"></param>
        /// <param name="offset_y"></param>
        /// <returns></returns>
        protected static XmlDocument getXmlDocument(
            string device_name,
            string part_number,
            string serial_number,
            float focal_length_pixels,
            float focal_length_mm,
            float baseline_mm,
            float fov_degrees,
            int image_width, int image_height,
            polynomial[] lens_distortion_curve,
            float[] centre_of_distortion_x, float[] centre_of_distortion_y,
            float[] minimum_rms_error,
            float rotation, float scale,
            float offset_x, float offset_y,
            bool disable_rectification,
            bool disable_radial_correction,
            bool flip_left_image,
            bool flip_right_image)
        {
            //usage.Update("Get xml document, BaseVisionStereo, GetXmlDocument");
            
            // Create the document.
            XmlDocument doc = new XmlDocument();

            // Insert the xml processing instruction and the root node
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "ISO-8859-1", null);
            doc.PrependChild(dec);

            XmlNode commentnode = doc.CreateComment("Sentience 3D Perception System");
            doc.AppendChild(commentnode);

            XmlElement nodeCalibration = doc.CreateElement("Sentience");
            doc.AppendChild(nodeCalibration);

            XmlElement elem = getXml(doc, nodeCalibration,
                device_name,
                part_number,
                serial_number,
                focal_length_pixels,
                focal_length_mm,
                baseline_mm,
                fov_degrees,
                image_width, image_height,
                lens_distortion_curve,
                centre_of_distortion_x, centre_of_distortion_y,
                minimum_rms_error,
                rotation, scale,
                offset_x, offset_y,
                disable_rectification,
                disable_radial_correction,
                flip_left_image,
                flip_right_image);
            doc.DocumentElement.AppendChild(elem);

            return (doc);
        }
开发者ID:kasertim,项目名称:sentience,代码行数:77,代码来源:BaseVisionStereo.cs

示例15: CreateXMLFileForStoringUserOptions

        /// <summary>
        /// <c>CreateXMLFileForStoringUserOptions</c>
        /// creates xml file to store UserOptions either to select AutoDelete Emails after  uploading or not
        /// </summary>
        /// <param name="xLogOptions"></param>
        /// <returns></returns>
        public static bool CreateXMLFileForStoringUserOptions(XMLLogOptions xLogOptions)
        {
            try
            {
                //, Folder name, site url, authentication mode and credentials.
                XmlDocument xmlDoc = new XmlDocument();
                XmlElement elemRoot = null, elem = null;
                XmlNode root = null;
                bool isNewXMlFile = true;

                UserLogManagerUtility.CheckItopiaDirectoryExits();

                //Check file is existed or not
                if (System.IO.File.Exists(UserLogManagerUtility.XMLOptionsFilePath) == true)
                {
                    //Save the details in Xml file
                    xmlDoc.Load(UserLogManagerUtility.XMLOptionsFilePath);
                    xmlDoc.RemoveAll();
                }

                XmlDeclaration xmlDec = xmlDoc.CreateXmlDeclaration("1.0", "utf-8", String.Empty);
                xmlDoc.PrependChild(xmlDec);
                XmlElement docRoot = xmlDoc.CreateElement("UserOptionsLog");
                xmlDoc.AppendChild(docRoot);

                //Create root node
                elemRoot = xmlDoc.CreateElement("Options");
                docRoot.AppendChild(elemRoot);

                elem = xmlDoc.CreateElement("AutoDeleteEmails");
                elem.InnerText = Convert.ToString(xLogOptions.AutoDeleteEmails);
                elemRoot.AppendChild(elem);

                if (isNewXMlFile == false)
                {
                    //XML file already existed add the node to xml file
                    root.InsertBefore(elemRoot, root.FirstChild);
                }
                //Save xml file
                xmlDoc.Save(UserLogManagerUtility.XMLOptionsFilePath);

                return true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return false;
        }
开发者ID:imysecy,项目名称:SPLINK,代码行数:55,代码来源:UserLogManagerUtility.cs


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