本文整理汇总了C#中Element.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# Element.AddChild方法的具体用法?C# Element.AddChild怎么用?C# Element.AddChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Element
的用法示例。
在下文中一共展示了Element.AddChild方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteParams
public static Element WriteParams(ArrayList Params)
{
if (Params != null && Params.Count > 0)
{
Element elParams = new Element("params");
for (int i = 0; i < Params.Count; i++)
{
Element param = new Element("param");
WriteValue(Params[i], param);
elParams.AddChild(param);
}
return elParams;
}
return null;
}
示例2: WriteCall
/// <summary>
/// Write the functions call with params to this Element
/// </summary>
/// <param name="name"> </param>
/// <param name="Params"> </param>
public void WriteCall(string name, ArrayList Params)
{
MethodName = name;
if (Params != null && Params.Count > 0)
{
// remote this tag if exists, in case this function gets
// calles multiple times by some guys
RemoveTag("params");
var elParams = new Element("params");
for (int i = 0; i < Params.Count; i++)
{
var param = new Element("param");
WriteValue(Params[i], param);
elParams.AddChild(param);
}
AddChild(elParams);
}
}
示例3: WriteValue
/// <summary>
/// Writes a single value to a call
/// </summary>
/// <param name="param"> </param>
/// <param name="parent"> </param>
private void WriteValue(object param, Element parent)
{
var value = new Element("value");
if (param is String)
{
value.AddChild(new Element("string", param as string));
}
else if (param is Int32)
{
value.AddChild(new Element("i4", ((Int32) param).ToString()));
}
else if (param is Double)
{
var numberInfo = new NumberFormatInfo();
numberInfo.NumberDecimalSeparator = ".";
//numberInfo.NumberGroupSeparator = ",";
value.AddChild(new Element("double", ((Double) param).ToString(numberInfo)));
}
else if (param is Boolean)
{
value.AddChild(new Element("boolean", ((bool) param) ? "1" : "0"));
}
// XML-RPC dates are formatted in iso8601 standard, same as xmpp,
else if (param is DateTime)
{
value.AddChild(new Element("dateTime.iso8601", Time.ISO_8601Date((DateTime) param)));
}
// byte arrays must be encoded in Base64 encoding
else if (param is byte[])
{
var b = (byte[]) param;
value.AddChild(new Element("base64", Convert.ToBase64String(b, 0, b.Length)));
}
// Arraylist maps to an XML-RPC array
else if (param is ArrayList)
{
//<array>
// <data>
// <value> <string>one</string> </value>
// <value> <string>two</string> </value>
// <value> <string>three</string></value>
// </data>
//</array>
var array = new Element("array");
var data = new Element("data");
var list = param as ArrayList;
for (int i = 0; i < list.Count; i++)
{
WriteValue(list[i], data);
}
array.AddChild(data);
value.AddChild(array);
}
// java.util.Hashtable maps to an XML-RPC struct
else if (param is Hashtable)
{
var elStruct = new Element("struct");
var ht = (Hashtable) param;
IEnumerator myEnumerator = ht.Keys.GetEnumerator();
while (myEnumerator.MoveNext())
{
var member = new Element("member");
object key = myEnumerator.Current;
member.AddChild(new Element("name", key.ToString()));
WriteValue(ht[key], member);
elStruct.AddChild(member);
}
value.AddChild(elStruct);
}
else
{
// Unknown Type
}
parent.AddChild(value);
}
示例4: Send
public override void Send(Element e)
{
// this is a hack to not send the xmlns="jabber:component:accept" with all packets
Element dummyEl = new Element("a");
dummyEl.Namespace = Uri.ACCEPT;
dummyEl.AddChild(e);
string toSend = dummyEl.ToString();
Send(toSend.Substring(35, toSend.Length - 35 - 4));
}
示例5: Message2
private void Message2()
{
// transient message (will not be stored offline if the server support AMP)
/*
<message to='[email protected]'
from='[email protected]/elsinore'
type='chat'
id='chatty1'>
<body>Who's there?</body>
<amp xmlns='http://jabber.org/protocol/amp'>
<rule action='drop' condition='deliver' value='stored'/>
</amp>
</message>
*/
agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
msg.To = new Jid("[email protected]");
msg.From = new Jid("[email protected]/elsinore");
msg.Type = MessageType.chat;
msg.Id = "chatty1";
msg.Body = "Who's there?";
Element amp = new Element();
amp.TagName = "amp";
amp.Namespace = "http://jabber.org/protocol/amp";
Element rule = new Element();
rule.TagName = "rule";
rule.Namespace = "http://jabber.org/protocol/amp";
rule.SetAttribute("action", "drop");
rule.SetAttribute("condition", "deliver");
rule.SetAttribute("value", "stored");
amp.AddChild(rule);
msg.AddChild(amp);
Program.Print(msg);
}
示例6: ToElement
public static IElement ToElement(this HtmlNode self, INode parent)
{
if (self == null)
throw new ArgumentNullException("self");
if (parent == null)
throw new ArgumentNullException("parent");
var name = self.ToQualifiedName();
var element = new Element(parent, name);
foreach (var attribute in self.ToAttributes(element))
element.AddAttribute(attribute);
foreach (var child in self.ToChildren(element))
element.AddChild(child);
var customElement = GetCustomElement(element, parent, name);
if (customElement != null)
{
foreach (var attribute in self.ToAttributes(customElement))
customElement.AddAttribute(attribute);
foreach (var child in self.ToChildren(customElement))
customElement.AddChild(child);
return customElement;
}
return element;
}
示例7: Send
public override void Send(Element e)
{
if (!(ClientSocket is BoshClientSocket))
{
// this is a hack to not send the xmlns="jabber:client" with all packets
Element dummyEl = new Element("a");
dummyEl.Namespace = Uri.CLIENT;
dummyEl.AddChild(e);
string toSend = dummyEl.ToString();
Send(toSend.Substring(25, toSend.Length - 25 - 4));
}
else
base.Send(e);
}
示例8: CreateInstructionsMenu
private void CreateInstructionsMenu(Element menu)
{
TextWidget text = new TextWidget();
text.Font = Fonts.Instance.TanksAltFont;
text.Location = new Vector(BattleGame.ResolutionX / 2, 350);
text.Size = new Vector(300, 280);
text.Text = "Arrow keys - movement,\nSpace - fire,\nP - pause,\nEscape - main menu";
text.Enabled = false;
menu.AddChild(text);
}
示例9: CreateAboutMenuContent
private void CreateAboutMenuContent(Element menu)
{
TextWidget text = new TextWidget();
text.Font = Fonts.Instance.TanksAltFont;
text.Location = new Vector(BattleGame.ResolutionX / 2, 350);
text.Size = new Vector(600, 280);
{
var gameInfo = "Simple Tanks game (based on Vortex2D.NET).\n";
var courseInfo = "Course - The Perspective Software\n";
var lecturerInfo = "Lecturer - Druzhinin U.V.\n";
var studentsInfo = "Students - Zhdanov A.V., Shaihutdinov R.G.\n";
text.Text = gameInfo + courseInfo + lecturerInfo + studentsInfo;
text.Enabled = false;
}
menu.AddChild(text);
}
示例10: AddChild
private void AddChild(Element parent)
{
TypeBrowser browser = TypeBrowser.Create(parent.GetType());
Element child = this.GetElement();
if (child is UnknownElement)
{
PropertyInfo property = browser.FindElement(this.GetXmlComponent());
if (property != null)
{
AssignValue(parent, property, child.InnerText);
// We're not going to add it to the parent, which has the potential to
// lose any attributes/child elements assigned to the unknown, but this
// is the behaviour of the C++ version.
return;
}
}
else if (parent.AddChild(child))
{
this.OnElementAdded(child); // Call it here after it's Parent has been set
return; // Not an orphan
}
else // Lets try an Element as a proprty?
{
this.OnElementAdded(child); // Will be either added as a Property or Orphan
// Search for a property that we can assign to
Type type = child.GetType();
foreach (var property in browser.Elements)
{
if (property.Item1.PropertyType.IsAssignableFrom(type))
{
property.Item1.SetValue(parent, child, null);
return;
}
}
}
parent.AddOrphan(child); // Save for later serialization
}
示例11: AddElement
private void AddElement(Element element, Element parent)
{
if (element != null)
{
AddElementToMap(element);
if (parent != null)
{
parent.AddChild(element);
}
}
}