本文整理匯總了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;
}
示例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;
}
示例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.");
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
//.........這裏部分代碼省略.........