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


C# XmlDocument.AddElement方法代码示例

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


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

示例1: WriteComponent

        protected XmlDocument WriteComponent(string element, ComponentMappingBase mapping)
        {
            var doc = new XmlDocument();
            var componentElement = doc.AddElement(element);

            if (mapping.HasValue(x => x.Name))
                componentElement.WithAtt("name", mapping.Name);

            if (mapping.HasValue(x => x.Insert))
                componentElement.WithAtt("insert", mapping.Insert);

            if (mapping.HasValue(x => x.Update))
                componentElement.WithAtt("update", mapping.Update);

            if (mapping.HasValue(x => x.Access))
                componentElement.WithAtt("access", mapping.Access);

            if (mapping.HasValue(x => x.Lazy))
                componentElement.WithAtt("lazy", mapping.Lazy);

            if (mapping.HasValue(x => x.OptimisticLock))
                componentElement.WithAtt("optimistic-lock", mapping.OptimisticLock);

            return doc;
        }
开发者ID:sbakshi,项目名称:fluent-nhibernate,代码行数:25,代码来源:BaseXmlComponentWriter.cs

示例2: DoFormatResponse

        protected override string DoFormatResponse(Dictionary<string, string> parameters)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement root = doc.AddElement(ROOT_ELEMENT);
            foreach (KeyValuePair<string, string> kvp in parameters)
            {
                root.AddElement(kvp.Key, kvp.Value);
            }

            return doc.OuterXml;
        }
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:11,代码来源:EventActionWebhookResponseHandlerXmlTests.cs

示例3: UnitTest_That_An_Element_Can_Be_Added

 public void UnitTest_That_An_Element_Can_Be_Added()
 {
     XmlDocument xmlDocument = new XmlDocument();
     xmlDocument
         .AddElement("MyDocumentElement", "http://schemas.acme.com/PetShop")
             .AddElement("MyChildElement1")
                 .AddAttribute("myAttrib", "myAttribValue")
                 .AddValue("MyChildElementValue")
                 .Parent()
             .AddElement("MyChildElement2")
                 .Parent()
             .AddElement("MyChildElement2")
             .AddElementBefore("MyChildElement3")
             .AddElementAfter("MyChildElement4");
     Assert.AreEqual(TestAddElementResult, xmlDocument.OuterXml);
     XmlElement childElement = xmlDocument.DocumentElement.Child("MyChildElement2");
     Assert.IsNotNull(childElement, "The child returned was null when it was not expected to be.");
 }
开发者ID:StealFocus,项目名称:BclExtensions,代码行数:18,代码来源:XmlDocumentExtensionsTests.cs

示例4: WriteComponent

        protected XmlDocument WriteComponent(string element, IComponentMapping mapping)
        {
            var doc = new XmlDocument();
            var componentElement = doc.AddElement(element);

            if (mapping.HasValue("Name"))
                componentElement.WithAtt("name", mapping.Name);

            if (mapping.HasValue("Insert"))
                componentElement.WithAtt("insert", mapping.Insert);

            if (mapping.HasValue("Update"))
                componentElement.WithAtt("update", mapping.Update);

            if (mapping.HasValue("Access"))
                componentElement.WithAtt("access", mapping.Access);

            if (mapping.HasValue("OptimisticLock"))
                componentElement.WithAtt("optimistic-lock", mapping.OptimisticLock);

            return doc;
        }
开发者ID:roelofb,项目名称:fluent-nhibernate,代码行数:22,代码来源:BaseXmlComponentWriter.cs

示例5: OnWriteToStream

        public override void OnWriteToStream(Type type, object value, System.IO.Stream stream, HttpContentHeaders contentHeaders, System.Net.TransportContext context)
        {
            var contacts = (IEnumerable<Contact>)value;

              var doc = new XmlDocument();
              var root = doc.AddElement("Root");

              // always emit the contacts collection, even if it's empty (we need the URI!)
              var contactsXml = root.AddElement("Contacts");
              contactsXml.SetAttribute("href", string.Format("{0}/contacts", this.baseUri));

              if (contacts.Count() > 0)
              {
            foreach (var contact in contacts)
            {
              HandleContact(contactsXml, contact);
            }
              }

              // always emit the queries, too!
              HandleQueries(root);

              doc.Save(stream);
        }
开发者ID:emmanuelfe,项目名称:HypermediaContacts,代码行数:24,代码来源:ContactsMediaTypeFormatterXml.cs

示例6: GetXmlRequestContent

        /// <summary>
        /// Gets the request content as an XML string.
        /// </summary>
        /// <param name="rootName">The name of the root container node.</param>
        /// <param name="application">The application.</param>
        /// <param name="requestFieldMap">The request field map.</param>
        /// <returns>The request content as an XML string.</returns>
        private string GetXmlRequestContent(string rootName, Application application, MappedFieldList requestFieldMap)
        {
            XmlEndpointRequestMapper xmlFieldMapper = new XmlEndpointRequestMapper();
            XmlDocument doc = new XmlDocument();
            doc.AddElement(rootName);
            xmlFieldMapper.Map(application, requestFieldMap, doc);

            return doc.OuterXml;
        }
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:16,代码来源:HttpWebRequestFactory.cs

示例7: CreateTemplateXmlElement

 private static XmlElement CreateTemplateXmlElement(XmlDocument xmlDoc, IContentClassFolder folder)
 {
     XmlElement template = xmlDoc.AddElement("TEMPLATE");
     template.AddAttribute("action", "addnew");
     template.AddAttribute("folderguid", folder.Guid.ToRQLString());
     return template;
 }
开发者ID:erminas,项目名称:smartapi,代码行数:7,代码来源:IContentClass.cs

示例8: Save

		public void Save(string filename, bool compressed = true)
		{
			XmlDocument fileData = new XmlDocument();
			
            #region Root speichern und Attribute anhängen
            XmlNode root=fileData.AddRoot("map");

            fileData.AddAttribute(root, "version", MapVersion);
            fileData.AddAttribute(root, "orientation", Orientation);

            fileData.AddAttribute(root, "width", Width);
            fileData.AddAttribute(root, "height", Height);

            fileData.AddAttribute(root, "tilewidth", TileWidth);
            fileData.AddAttribute(root, "tileheight", TileHeight);
            #endregion

            #region Properties speichern
            if(Properties.Count>0)
            {
                XmlNode properties=fileData.AddElement(root, "properties");

                foreach(Property prop in Properties)
                {
                    XmlNode propertyXml=fileData.AddElement(properties, "property");
                    fileData.AddAttribute(propertyXml, "name", prop.Name);
                    fileData.AddAttribute(propertyXml, "value", prop.Value);
                }
            }
            #endregion

            #region Tilesets
            foreach(TilesetData tileset in Tilesets)
            {
                XmlNode tilesetXml=fileData.AddElement(root, "tileset");
                fileData.AddAttribute(tilesetXml, "firstgid", tileset.firstgid);
                fileData.AddAttribute(tilesetXml, "name", tileset.name);
                fileData.AddAttribute(tilesetXml, "tilewidth", tileset.tilewidth);
                fileData.AddAttribute(tilesetXml, "tileheight", tileset.tileheight);

                XmlNode imageTag=fileData.AddElement(tilesetXml, "image");
                fileData.AddAttribute(imageTag, "source", tileset.imgsource);

                foreach(Tile tile in tileset.Tiles)
                {
                    XmlNode tileTag=fileData.AddElement(tilesetXml, "tile");
                    fileData.AddAttribute(tileTag, "id", tile.ID);

                    if(tile.Properties.Count>0)
                    {
                        XmlNode properties=fileData.AddElement(tileTag, "properties");

                        foreach(Property prop in tile.Properties)
                        {
                            XmlNode propertyXml=fileData.AddElement(properties, "property");
                            fileData.AddAttribute(propertyXml, "name", prop.Name);
                            fileData.AddAttribute(propertyXml, "value", prop.Value);
                        }
                    }
                }

            }
            #endregion

            #region Layer
            foreach(LayerData layer in Layers)
            {
                XmlNode layerXml=fileData.AddElement(root, "layer");
                fileData.AddAttribute(layerXml, "name", layer.name);
                fileData.AddAttribute(layerXml, "width", layer.width);
                fileData.AddAttribute(layerXml, "height", layer.height);

                XmlNode dataTag=fileData.AddElement(layerXml, "data", ConvertLayerDataToString(layer, compressed));
                fileData.AddAttribute(dataTag, "encoding", "base64");

                if(compressed)
                {
                    fileData.AddAttribute(dataTag, "compression", "gzip");
                }
            }
            #endregion

            #region Objectlayer
            foreach(Objectgroup objGroup in ObjectLayers)
            {
                XmlNode objGroupXml=fileData.AddElement(root, "objectgroup");
                fileData.AddAttribute(objGroupXml, "name", objGroup.Name);
                fileData.AddAttribute(objGroupXml, "width", objGroup.Width);
                fileData.AddAttribute(objGroupXml, "height", objGroup.Height);
                fileData.AddAttribute(objGroupXml, "x", objGroup.X);
                fileData.AddAttribute(objGroupXml, "y", objGroup.Y);

                foreach(Object obj in objGroup.Objects)
                {
                    XmlNode objXml=fileData.AddElement(objGroupXml, "object");
                    fileData.AddAttribute(objXml, "name", obj.Name);
                    fileData.AddAttribute(objXml, "type", obj.Type);
                    fileData.AddAttribute(objXml, "x", obj.X);
                    fileData.AddAttribute(objXml, "y", obj.Y);
                    fileData.AddAttribute(objXml, "width", obj.Width);
//.........这里部分代码省略.........
开发者ID:Xevle,项目名称:Xevle.FileFormats.TMX,代码行数:101,代码来源:TMX.cs


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