本文整理汇总了C#中XmlNode.AppendChild方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNode.AppendChild方法的具体用法?C# XmlNode.AppendChild怎么用?C# XmlNode.AppendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlNode
的用法示例。
在下文中一共展示了XmlNode.AppendChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateNode
public XmlNode CreateNode(XmlDocument doc, XmlNode parent, string node_label, string node_value)
{
XmlNode node = doc.CreateElement(node_label);
node.InnerText = node_value;
parent.AppendChild(node);
return node;
}
示例2: SetPropNode
public static void SetPropNode(XmlNode parent, XmlNode child)
{
foreach (XmlNode toRemove in parent.Children(child.Name).ToArray()) {
parent.RemoveChild(toRemove);
}
parent.AppendChild(child);
Save();
}
示例3: AddXMLChildNode
public static XmlNode AddXMLChildNode(XmlDocument xmlDoc, XmlNode xmlnodeRoot, string sElementName)
{
XmlNode xmlnodeChild;
XmlElement xmlElemChild;
xmlElemChild = xmlDoc.CreateElement("", sElementName, "");
xmlnodeChild = xmlnodeRoot.AppendChild(xmlElemChild);
return xmlnodeChild;
}
示例4: InjectXmlNodeList
public void InjectXmlNodeList(XmlNodeList nodeList)
{
XmlDocument doc = new XmlDocument();
xmlNode = doc.CreateElement("root");
foreach(XmlNode _node in nodeList)
{
xmlNode.AppendChild(_node);
}
RegisterEventHandlers();
}
示例5: AddSongsInAlbum
static void AddSongsInAlbum(XmlDocument xml, Dictionary<string, double> songsList, XmlNode album)
{
foreach (var songName in songsList)
{
XmlNode song = album.AppendChild(xml.CreateElement("Song"));
XmlNode title = song.AppendChild(xml.CreateElement("Title"));
XmlNode duration = song.AppendChild(xml.CreateElement("Duration"));
title.InnerText = songName.Key;
duration.InnerText = songName.Value.ToString();
}
}
示例6: AddXMLElement
public static XmlNode AddXMLElement(XmlDocument xmlDoc, XmlNode xmlnode, string sElementName, string sElementValue, bool bElementOnly)
{
XmlElement xmlelem;
XmlText xmltext;
XmlNode newnode;
xmlelem = xmlDoc.CreateElement("", sElementName, "");
if (!bElementOnly)
{
xmltext = xmlDoc.CreateTextNode(sElementValue);
xmlelem.AppendChild(xmltext);
}
newnode = xmlnode.AppendChild(xmlelem);
return newnode;
}
示例7: AppendElement
public static XmlElement AppendElement(XmlNode target, string elementName, object inner)
{
try{
XmlElement e = target.OwnerDocument.CreateElement(elementName);
if(inner is XmlNode){
XmlNode innerNode = inner as XmlNode;
if(string.IsNullOrEmpty(innerNode.InnerText)) return null;
e.AppendChild(innerNode);
target.AppendChild(e);
return e;
}
if(string.IsNullOrEmpty(inner.ToString())) return null;
e.InnerText = inner.ToString();
target.AppendChild(e);
return e;
}catch (Exception e){
Console.Error.WriteLine("[{0}]", target);
Console.Error.WriteLine("[{0}]", elementName);
Console.Error.WriteLine("[{0}]", inner);
Console.Error.WriteLine(e);
throw;
}
}
示例8: AddAlbum
static XmlNode AddAlbum(XmlDocument xml, XmlNode catalogue, string albumName, string artistName, string year, string producerName, decimal price)
{
XmlNode artist = catalogue.AppendChild(xml.CreateElement("Artist"));
XmlAttribute artistAttrName = artist.Attributes.Append(xml.CreateAttribute("name"));
artistAttrName.InnerText = artistName;
XmlNode album = AddChild(xml, artist, "Album");
XmlAttribute albumAttrName = album.Attributes.Append(xml.CreateAttribute("name"));
albumAttrName.InnerText = albumName;
XmlNode promYear = AddChild(xml, album, "Year");
promYear.InnerText = year;
XmlNode producer = AddChild(xml, album, "Producer");
producer.InnerText = producerName;
XmlNode albumPrice = AddChild(xml, album, "Price");
albumPrice.InnerText = price.ToString();
XmlNode songs = AddChild(xml, album, "Songs");
return album;
}
示例9: ProcessAppInfoDocMarkup
private void ProcessAppInfoDocMarkup(bool root) {
//First time reader is positioned on AppInfo or Documentation element
XmlNode currentNode = null;
switch (reader.NodeType) {
case XmlNodeType.Element:
annotationNSManager.PushScope();
currentNode = LoadElementNode(root);
break;
case XmlNodeType.Text:
currentNode = dummyDocument.CreateTextNode( reader.Value );
goto default;
case XmlNodeType.SignificantWhitespace:
currentNode = dummyDocument.CreateSignificantWhitespace( reader.Value );
goto default;
case XmlNodeType.CDATA:
currentNode = dummyDocument.CreateCDataSection( reader.Value );
goto default;
case XmlNodeType.EntityReference:
currentNode = dummyDocument.CreateEntityReference( reader.Name );
goto default;
case XmlNodeType.Comment:
currentNode = dummyDocument.CreateComment( reader.Value );
goto default;
case XmlNodeType.ProcessingInstruction:
currentNode = dummyDocument.CreateProcessingInstruction( reader.Name, reader.Value );
goto default;
case XmlNodeType.EndEntity:
break;
case XmlNodeType.Whitespace:
break;
case XmlNodeType.EndElement:
annotationNSManager.PopScope();
parentNode = parentNode.ParentNode;
break;
default: //other possible node types: Document/DocType/DocumentFrag/Entity/Notation/Xmldecl cannot appear as children of xs:appInfo or xs:doc
Debug.Assert(currentNode != null);
Debug.Assert(parentNode != null);
parentNode.AppendChild(currentNode);
break;
}
}
示例10: AddItem
///<summary>
///</summary>
///<param name="Element"></param>
///<param name="Key"></param>
///<param name="value"></param>
public void AddItem(XmlNode Element, string Key, string value)
{
XmlNode ItemElement = CreateNode(XmlNodeType.Element, "Item", "");
ItemElement.Attributes.Append(AddAttribute("key", Key));
ItemElement.Attributes.Append(AddAttribute("value", value));
Element.AppendChild(ItemElement);
}
示例11: AddChild
static XmlNode AddChild(XmlDocument xml, XmlNode node, string nodeName)
{
XmlNode newNode = node.AppendChild(xml.CreateElement(nodeName));
return newNode;
}
示例12: AddDictionaryToPlist
static void AddDictionaryToPlist (ISD_Variable var, XmlNode node, XmlDocument doc)
{
if(var.DictValues.Count == 0) return;
foreach(ISD_VariableListed varDict in var.DictValues)
{
XmlNode tempNode = null;
switch(varDict.Type)
{
case ISD_PlistValueTypes.Boolean:
tempNode = doc.CreateElement (varDict.BooleanValue.ToString ().ToLower ());
break;
case ISD_PlistValueTypes.Float:
tempNode = doc.CreateElement ("real");
tempNode.InnerText = varDict.FloatValue.ToString ();
break;
case ISD_PlistValueTypes.Integer:
tempNode = doc.CreateElement ("integer");
tempNode.InnerText = varDict.IntegerValue.ToString ();
break;
case ISD_PlistValueTypes.String:
tempNode = doc.CreateElement ("string");
tempNode.InnerText = varDict.StringValue;
break;
}
XmlNode tempKeyNode = doc.CreateElement ("key");
tempKeyNode.InnerText = varDict.DictKey;
node.AppendChild (tempKeyNode);
node.AppendChild (tempNode);
}
}
示例13: AddArrayToPlist
static void AddArrayToPlist (ISD_Variable var, XmlNode node, XmlDocument doc)
{
if(var.ArrayValue.Count == 0) return;
foreach(ISD_VariableListed varArray in var.ArrayValue)
{
switch(var.ArrayType)
{
case ISD_PlistValueTypes.Boolean:
XmlNode tempBoolNode = doc.CreateElement (varArray.BooleanValue.ToString ().ToLower ());
node.AppendChild (tempBoolNode);
break;
case ISD_PlistValueTypes.Float:
XmlNode tempFloatNode = doc.CreateElement ("real");
tempFloatNode.InnerText = varArray.FloatValue.ToString ();
node.AppendChild (tempFloatNode);
break;
case ISD_PlistValueTypes.Integer:
XmlNode tempIntegerNode = doc.CreateElement ("integer");
tempIntegerNode.InnerText = varArray.IntegerValue.ToString ();
node.AppendChild (tempIntegerNode);
break;
case ISD_PlistValueTypes.String:
XmlNode tempStringNode = doc.CreateElement ("string");
tempStringNode.InnerText = varArray.StringValue;
node.AppendChild (tempStringNode);
break;
}
}
}
示例14: createTextWallNodes
public static XmlNode createTextWallNodes(XmlDocument HomeSettings, XmlNode CurrNode, string element, string innertext)
{
XmlElement NewNodes = HomeSettings.CreateElement(element);
NewNodes.InnerText = NewNodes.InnerText = innertext;
///CurrNode.PrependChild(NewNodes);
CurrNode.AppendChild(NewNodes);
//CurrNode.LastChild
// CurrNode.InsertAfter( NewNodes, CurrNode.LastChild );
return CurrNode;
}
示例15: SaveValueToPlistNode
private static bool SaveValueToPlistNode(XmlNode node, object value)
{
// The node passed will be the parent node to the new value node.
XmlNode valNode;
System.Type type = value.GetType();
// Identify the data type for the value and serialize it accordingly
if (type == typeof(String)) {
valNode = node.OwnerDocument.CreateElement("string");
}
else if (type == typeof(Int16) ||
type == typeof(Int32) ||
type == typeof(Int64)) { valNode = node.OwnerDocument.CreateElement("integer"); }
else if (type == typeof(Single) ||
type == typeof(Double) ||
type == typeof(Decimal)) { valNode = node.OwnerDocument.CreateElement("real"); }
else if (type == typeof(DateTime)) {
// Dates need to be stored in ISO 8601 format
valNode = node.OwnerDocument.CreateElement("date");
DateTime dt = (DateTime)value;
valNode.InnerText = dt.ToUniversalTime().ToString("o");
node.AppendChild(valNode);
return true;
}
else if (type == typeof(bool)) {
// Boolean values are empty elements, simply being stored as an elemement with a name of true or false
if ((bool)value == true) { valNode = node.OwnerDocument.CreateElement("true"); }
else { valNode = node.OwnerDocument.CreateElement("false"); }
node.AppendChild(valNode);
return true;
}
// Hashtables and arrays require special functions to save their values in an itterative and recursive manner.
// The functions will return true/false to indicate success/failure, so pass those on.
else if (type == typeof(Hashtable)) {
return SaveDictToPlistNode(node, (Hashtable)value);
}
else if (type == typeof(ArrayList)) { return SaveArrayToPlistNode(node, (ArrayList)value); }
// Anything that doesn't fit the defined data types will just be stored as "data", which is effectively a string.
else {
valNode = node.OwnerDocument.CreateElement("data");
}
// Some of the values (strings, numbers, data) basically get stored as a string. The rest will store their values in their special format and return true for success. If we made it this far, then the value in valNode must be stored as a string.
if (valNode != null) valNode.InnerText = value.ToString();
node.AppendChild(valNode);
// We're done. Return true for success.
return true;
}