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; }
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; }
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."); }
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; }
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); }
/// <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; }
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; }
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); fileData.AddAttribute(objXml, "height", obj.Height); XmlNode objPropertiesXml=fileData.AddElement(objXml, "properties"); foreach(Property objProp in obj.Properties) { XmlNode propertyXml=fileData.AddElement(objPropertiesXml, "property"); fileData.AddAttribute(propertyXml, "name", objProp.Name); fileData.AddAttribute(propertyXml, "value", objProp.Value); } } } #endregion fileData.Save(filename); }