本文整理匯總了C#中System.Xml.Linq.XContainer.Add方法的典型用法代碼示例。如果您正苦於以下問題:C# XContainer.Add方法的具體用法?C# XContainer.Add怎麽用?C# XContainer.Add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XContainer
的用法示例。
在下文中一共展示了XContainer.Add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: addCmsSitemap
private static void addCmsSitemap(XContainer xml)
{
var pages = Cache.Pages.GroupBy(p => p.Category);
foreach (var category in pages)
{
var categoryName = category.Key.ToLower();
if (!categoryName.Matches("Home"))
xml.Add(urlElementFor(Settings.Domain + "/" + categoryName));
foreach (var page in category.Where(p => !p.Category.Matches("Home") && p.Crawl))
xml.Add(urlElementFor(page.FullURL));
}
}
示例2: AddElements
protected virtual void AddElements(XContainer root)
{
XContainer events = new XElement("events");
XContainer eventEntity = new XElement("event");
root.Add(new XElement("import-id", 1));
root.Add(new XElement("user-id", "ABC"));
root.Add(new XElement("echo", "123"));
eventEntity.Add(new XElement("description", "This is a test response"));
eventEntity.Add(new XElement("event-type", "SUBMITTING"));
eventEntity.Add(new XElement("status", "INPROGRESS"));
eventEntity.Add(new XElement("value", "50"));
events.Add(eventEntity);
root.Add(events);
}
示例3: AddNode
private static void AddNode(XContainer parent, ParseTreeNode node)
{
var element = new XElement(node.Name.Length == 0 ? "root" : node.Name,
new XAttribute("data", node.Text));
parent.Add(element);
if (node.Children != null)
node.Children.Do(child => AddNode(element, child));
}
示例4: UpdatePropertyElement
/// <summary>
/// Updates the property element.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="elementPosition">The element position.</param>
/// <param name="fileId">The file id.</param>
private static void UpdatePropertyElement(XContainer property, SourceElementPosition elementPosition, string fileId)
{
property.Add(new XElement("FileRef", new XAttribute("uid", fileId)));
var seqpnt = new XElement(
"SequencePoint",
new XAttribute("vc", property.Element("MethodPoint").Attribute("vc").Value),
new XAttribute("sl", elementPosition.Start));
property.Element("SequencePoints").Add(seqpnt);
}
示例5: CompileRecursive
private void CompileRecursive(ConnectionInfo serializationTarget, XContainer parentElement)
{
var newElement = parentElement;
if (!(serializationTarget is RootNodeInfo))
{
newElement = CompileConnectionInfoNode(serializationTarget);
parentElement.Add(newElement);
}
var serializationTargetAsContainer = serializationTarget as ContainerInfo;
if (serializationTargetAsContainer == null) return;
foreach (var child in serializationTargetAsContainer.Children)
CompileRecursive(child, newElement);
}
示例6: UpdateMethodElement
/// <summary>
/// Updates the method element.
/// </summary>
/// <param name="method">The method.</param>
/// <param name="elementPosition">The element position.</param>
/// <param name="fileId">The file id.</param>
private static void UpdateMethodElement(XContainer method, SourceElementPosition elementPosition, string fileId)
{
for (int i = elementPosition.Start; i <= elementPosition.End; i++)
{
var seqpnt = new XElement(
"pt",
new XAttribute("visit", "0"),
new XAttribute("fid", fileId),
new XAttribute("sl", i));
method.Add(seqpnt);
}
}
示例7: AddNewFile
/// <summary>
/// Adds a new source code file to the report.
/// </summary>
/// <param name="filesContainer">The files container.</param>
/// <param name="fileId">The file id.</param>
/// <param name="file">The file path.</param>
protected override void AddNewFile(XContainer filesContainer, string fileId, string file)
{
XDocument document = filesContainer as XDocument;
if (document != null)
{
document.Root.Add(new XElement("File", new XAttribute("id", fileId), new XAttribute("url", file)));
}
else
{
filesContainer.Add(new XElement("File", new XAttribute("id", fileId), new XAttribute("url", file)));
}
}
示例8: addElementToNode
protected bool addElementToNode(XElement newElement, XContainer container)
{
try
{
container.Add(newElement);
this.saveDocument();
}
catch (System.Exception exception)
{
Console.WriteLine(this.ToString() + "->addElementToNode Exception. Err : " + exception.Message);
return false;
}
return true;
}
示例9: MappingWriter
public MappingWriter(DatabaseTable table, CodeWriterSettings codeWriterSettings)
{
_codeWriterSettings = codeWriterSettings;
var ns = codeWriterSettings.Namespace;
_table = table;
_doc = XDocument.Parse(@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<hibernate-mapping xmlns=""urn:nhibernate-mapping-2.2"" namespace=""" + ns + @""" assembly=""" + ns + @""">
</hibernate-mapping>");
var hibmap = _doc.Descendants(_xmlns + "hibernate-mapping").First();
//add the class element
_classElement = new XElement(_xmlns + "class",
new XAttribute("name", _table.NetName),
new XAttribute("table", SqlSafe(_table.Name)),
_table.SchemaOwner != null ? new XAttribute("schema", SqlSafe(_table.SchemaOwner)) : null,
//consider this
new XAttribute("dynamic-update", "true"),
new XAttribute("optimistic-lock", "dirty"));
if (_table is DatabaseView)
{
_classElement.Add(new XAttribute("mutable", "false"));
}
hibmap.Add(_classElement);
}
示例10: Map
private void Map(XContainer root, object obj)
{
Type objType = obj.GetType();
IEnumerable<PropertyInfo> props = from p in objType.GetProperties()
let indexAttribute = p.GetAttribute<SerializeAsAttribute>()
where p.CanRead && p.CanWrite
orderby indexAttribute == null
? int.MaxValue
: indexAttribute.Index
select p;
SerializeAsAttribute globalOptions = objType.GetAttribute<SerializeAsAttribute>();
foreach (PropertyInfo prop in props)
{
string name = prop.Name;
object rawValue = prop.GetValue(obj, null);
if (rawValue == null)
{
continue;
}
string value = this.GetSerializedValue(rawValue);
Type propType = prop.PropertyType;
bool useAttribute = false;
SerializeAsAttribute settings = prop.GetAttribute<SerializeAsAttribute>();
if (settings != null)
{
name = settings.Name.HasValue()
? settings.Name
: name;
useAttribute = settings.Attribute;
}
SerializeAsAttribute options = prop.GetAttribute<SerializeAsAttribute>();
if (options != null)
{
name = options.TransformName(name);
}
else if (globalOptions != null)
{
name = globalOptions.TransformName(name);
}
XName nsName = name.AsNamespaced(this.Namespace);
XElement element = new XElement(nsName);
#if !WINDOWS_UWP
if (propType.IsPrimitive || propType.IsValueType || propType == typeof(string))
#else
if (propType.GetTypeInfo().IsPrimitive || propType.GetTypeInfo().IsValueType || propType == typeof(string))
#endif
{
if (useAttribute)
{
root.Add(new XAttribute(name, value));
continue;
}
element.Value = value;
}
else if (rawValue is IList)
{
string itemTypeName = "";
foreach (object item in (IList) rawValue)
{
if (itemTypeName == "")
{
Type type = item.GetType();
SerializeAsAttribute setting = type.GetAttribute<SerializeAsAttribute>();
itemTypeName = setting != null && setting.Name.HasValue()
? setting.Name
: type.Name;
}
XElement instance = new XElement(itemTypeName.AsNamespaced(this.Namespace));
this.Map(instance, item);
element.Add(instance);
}
}
else
{
this.Map(element, rawValue);
}
root.Add(element);
}
}
示例11: SetInheritanceAttributes
private void SetInheritanceAttributes(XContainer element, IInheritable connectionInfo)
{
if (_saveFilter.SaveInheritance)
{
element.Add(new XAttribute("InheritCacheBitmaps", connectionInfo.Inheritance.CacheBitmaps.ToString()));
element.Add(new XAttribute("InheritColors", connectionInfo.Inheritance.Colors.ToString()));
element.Add(new XAttribute("InheritDescription", connectionInfo.Inheritance.Description.ToString()));
element.Add(new XAttribute("InheritDisplayThemes", connectionInfo.Inheritance.DisplayThemes.ToString()));
element.Add(new XAttribute("InheritDisplayWallpaper", connectionInfo.Inheritance.DisplayWallpaper.ToString()));
element.Add(new XAttribute("InheritEnableFontSmoothing", connectionInfo.Inheritance.EnableFontSmoothing.ToString()));
element.Add(new XAttribute("InheritEnableDesktopComposition", connectionInfo.Inheritance.EnableDesktopComposition.ToString()));
element.Add(new XAttribute("InheritDomain", connectionInfo.Inheritance.Domain.ToString()));
element.Add(new XAttribute("InheritIcon", connectionInfo.Inheritance.Icon.ToString()));
element.Add(new XAttribute("InheritPanel", connectionInfo.Inheritance.Panel.ToString()));
element.Add(new XAttribute("InheritPassword", connectionInfo.Inheritance.Password.ToString()));
element.Add(new XAttribute("InheritPort", connectionInfo.Inheritance.Port.ToString()));
element.Add(new XAttribute("InheritProtocol", connectionInfo.Inheritance.Protocol.ToString()));
element.Add(new XAttribute("InheritPuttySession", connectionInfo.Inheritance.PuttySession.ToString()));
element.Add(new XAttribute("InheritRedirectDiskDrives", connectionInfo.Inheritance.RedirectDiskDrives.ToString()));
element.Add(new XAttribute("InheritRedirectKeys", connectionInfo.Inheritance.RedirectKeys.ToString()));
element.Add(new XAttribute("InheritRedirectPorts", connectionInfo.Inheritance.RedirectPorts.ToString()));
element.Add(new XAttribute("InheritRedirectPrinters", connectionInfo.Inheritance.RedirectPrinters.ToString()));
element.Add(new XAttribute("InheritRedirectSmartCards", connectionInfo.Inheritance.RedirectSmartCards.ToString()));
element.Add(new XAttribute("InheritRedirectSound", connectionInfo.Inheritance.RedirectSound.ToString()));
element.Add(new XAttribute("InheritSoundQuality", connectionInfo.Inheritance.SoundQuality.ToString()));
element.Add(new XAttribute("InheritResolution", connectionInfo.Inheritance.Resolution.ToString()));
element.Add(new XAttribute("InheritAutomaticResize", connectionInfo.Inheritance.AutomaticResize.ToString()));
element.Add(new XAttribute("InheritUseConsoleSession", connectionInfo.Inheritance.UseConsoleSession.ToString()));
element.Add(new XAttribute("InheritUseCredSsp", connectionInfo.Inheritance.UseCredSsp.ToString()));
element.Add(new XAttribute("InheritRenderingEngine", connectionInfo.Inheritance.RenderingEngine.ToString()));
element.Add(new XAttribute("InheritUsername", connectionInfo.Inheritance.Username.ToString()));
element.Add(new XAttribute("InheritICAEncryptionStrength", connectionInfo.Inheritance.ICAEncryptionStrength.ToString()));
element.Add(new XAttribute("InheritRDPAuthenticationLevel", connectionInfo.Inheritance.RDPAuthenticationLevel.ToString()));
element.Add(new XAttribute("InheritLoadBalanceInfo", connectionInfo.Inheritance.LoadBalanceInfo.ToString()));
element.Add(new XAttribute("InheritPreExtApp", connectionInfo.Inheritance.PreExtApp.ToString()));
element.Add(new XAttribute("InheritPostExtApp", connectionInfo.Inheritance.PostExtApp.ToString()));
element.Add(new XAttribute("InheritMacAddress", connectionInfo.Inheritance.MacAddress.ToString()));
element.Add(new XAttribute("InheritUserField", connectionInfo.Inheritance.UserField.ToString()));
element.Add(new XAttribute("InheritExtApp", connectionInfo.Inheritance.ExtApp.ToString()));
element.Add(new XAttribute("InheritVNCCompression", connectionInfo.Inheritance.VNCCompression.ToString()));
element.Add(new XAttribute("InheritVNCEncoding", connectionInfo.Inheritance.VNCEncoding.ToString()));
element.Add(new XAttribute("InheritVNCAuthMode", connectionInfo.Inheritance.VNCAuthMode.ToString()));
element.Add(new XAttribute("InheritVNCProxyType", connectionInfo.Inheritance.VNCProxyType.ToString()));
element.Add(new XAttribute("InheritVNCProxyIP", connectionInfo.Inheritance.VNCProxyIP.ToString()));
element.Add(new XAttribute("InheritVNCProxyPort", connectionInfo.Inheritance.VNCProxyPort.ToString()));
element.Add(new XAttribute("InheritVNCProxyUsername", connectionInfo.Inheritance.VNCProxyUsername.ToString()));
element.Add(new XAttribute("InheritVNCProxyPassword", connectionInfo.Inheritance.VNCProxyPassword.ToString()));
element.Add(new XAttribute("InheritVNCColors", connectionInfo.Inheritance.VNCColors.ToString()));
element.Add(new XAttribute("InheritVNCSmartSizeMode", connectionInfo.Inheritance.VNCSmartSizeMode.ToString()));
element.Add(new XAttribute("InheritVNCViewOnly", connectionInfo.Inheritance.VNCViewOnly.ToString()));
element.Add(new XAttribute("InheritRDGatewayUsageMethod", connectionInfo.Inheritance.RDGatewayUsageMethod.ToString()));
element.Add(new XAttribute("InheritRDGatewayHostname", connectionInfo.Inheritance.RDGatewayHostname.ToString()));
element.Add(new XAttribute("InheritRDGatewayUseConnectionCredentials", connectionInfo.Inheritance.RDGatewayUseConnectionCredentials.ToString()));
element.Add(new XAttribute("InheritRDGatewayUsername", connectionInfo.Inheritance.RDGatewayUsername.ToString()));
element.Add(new XAttribute("InheritRDGatewayPassword", connectionInfo.Inheritance.RDGatewayPassword.ToString()));
element.Add(new XAttribute("InheritRDGatewayDomain", connectionInfo.Inheritance.RDGatewayDomain.ToString()));
}
else
{
element.Add(new XAttribute("InheritCacheBitmaps", false.ToString()));
element.Add(new XAttribute("InheritColors", false.ToString()));
element.Add(new XAttribute("InheritDescription", false.ToString()));
element.Add(new XAttribute("InheritDisplayThemes", false.ToString()));
element.Add(new XAttribute("InheritDisplayWallpaper", false.ToString()));
element.Add(new XAttribute("InheritEnableFontSmoothing", false.ToString()));
element.Add(new XAttribute("InheritEnableDesktopComposition", false.ToString()));
element.Add(new XAttribute("InheritDomain", false.ToString()));
element.Add(new XAttribute("InheritIcon", false.ToString()));
element.Add(new XAttribute("InheritPanel", false.ToString()));
element.Add(new XAttribute("InheritPassword", false.ToString()));
element.Add(new XAttribute("InheritPort", false.ToString()));
element.Add(new XAttribute("InheritProtocol", false.ToString()));
element.Add(new XAttribute("InheritPuttySession", false.ToString()));
element.Add(new XAttribute("InheritRedirectDiskDrives", false.ToString()));
element.Add(new XAttribute("InheritRedirectKeys", false.ToString()));
element.Add(new XAttribute("InheritRedirectPorts", false.ToString()));
element.Add(new XAttribute("InheritRedirectPrinters", false.ToString()));
element.Add(new XAttribute("InheritRedirectSmartCards", false.ToString()));
element.Add(new XAttribute("InheritRedirectSound", false.ToString()));
element.Add(new XAttribute("InheritSoundQuality", false.ToString()));
element.Add(new XAttribute("InheritResolution", false.ToString()));
element.Add(new XAttribute("InheritAutomaticResize", false.ToString()));
element.Add(new XAttribute("InheritUseConsoleSession", false.ToString()));
element.Add(new XAttribute("InheritUseCredSsp", false.ToString()));
element.Add(new XAttribute("InheritRenderingEngine", false.ToString()));
element.Add(new XAttribute("InheritUsername", false.ToString()));
element.Add(new XAttribute("InheritICAEncryptionStrength", false.ToString()));
element.Add(new XAttribute("InheritRDPAuthenticationLevel", false.ToString()));
element.Add(new XAttribute("InheritLoadBalanceInfo", false.ToString()));
element.Add(new XAttribute("InheritPreExtApp", false.ToString()));
element.Add(new XAttribute("InheritPostExtApp", false.ToString()));
element.Add(new XAttribute("InheritMacAddress", false.ToString()));
element.Add(new XAttribute("InheritUserField", false.ToString()));
element.Add(new XAttribute("InheritExtApp", false.ToString()));
element.Add(new XAttribute("InheritVNCCompression", false.ToString()));
element.Add(new XAttribute("InheritVNCEncoding", false.ToString()));
element.Add(new XAttribute("InheritVNCAuthMode", false.ToString()));
element.Add(new XAttribute("InheritVNCProxyType", false.ToString()));
element.Add(new XAttribute("InheritVNCProxyIP", false.ToString()));
element.Add(new XAttribute("InheritVNCProxyPort", false.ToString()));
//.........這裏部分代碼省略.........
示例12: TraverseWithXDocument
private static void TraverseWithXDocument(XContainer document, string path)
{
bool inDirectories = true;
string[] folderDirectories = Directory.GetDirectories(path);
if (0 == folderDirectories.Length)
{
folderDirectories = Directory.GetFiles(path);
inDirectories = false;
}
for (int i = 0; i < folderDirectories.Length; i++)
{
if (inDirectories)
{
XAttribute attribute = new XAttribute("path", folderDirectories[i]);
XElement innerNode = new XElement("dir", attribute);
TraverseWithXDocument(innerNode, folderDirectories[i]);
document.Add(innerNode);
}
else
{
XAttribute attribute = new XAttribute("fileName", Path.GetFileName(folderDirectories[i]));
XElement innerNode = new XElement("file", attribute);
document.Add(innerNode);
}
}
}
示例13: WriteObject
private void WriteObject(string name, object value, XContainer parent, IDictionary<string, XNamespace> namespaces)
{
if(HaveCustomValueConvertor(value.GetType()))
{
var valueConvertorType = reflection.GetGenericTypeOf(typeof (IValueConvertor<>), value);
var convertor = serviceLocator.Resolve(valueConvertorType);
var elementName = GetXmlNamespace(namespaces, value.GetType()) + name;
var convertedValue = reflection.InvokeToElement(convertor, value, v => GetXmlNamespace(namespaces, v));
convertedValue = ApplyMessageSerializationBehaviorIfNecessary(value.GetType(), convertedValue);
parent.Add(new XElement(elementName, convertedValue));
}
else if(HaveCustomSerializer(value.GetType()))
{
var customSerializer = customElementSerializers.First(s => s.CanSerialize(value.GetType()));
var elementName = GetXmlNamespace(namespaces, value.GetType()) + name;
var element = customSerializer.ToElement(value, v => GetXmlNamespace(namespaces, v));
var customElement = new XElement(elementName, element);
customElement = ApplyMessageSerializationBehaviorIfNecessary(value.GetType(), customElement);
parent.Add(customElement);
}
else if (ShouldPutAsString(value))
{
var elementName = GetXmlNamespace(namespaces, value.GetType()) + name;
parent.Add(new XElement(elementName, FormatAsString(value)));
}
else if (value is byte[])
{
var elementName = GetXmlNamespace(namespaces, typeof(byte[])) + name;
parent.Add(new XElement(elementName, Convert.ToBase64String((byte[]) value)));
}
else if (ShouldTreatAsDictionary(value.GetType()))
{
XElement list = GetContentWithNamespace(value, namespaces, name);
parent.Add(list);
var itemCount = 0;
foreach (var item in ((IEnumerable)value))
{
if (item == null)
continue;
itemCount += 1;
if (itemCount > MaxNumberOfAllowedItemsInCollection)
throw new UnboundedResultSetException("You cannot send collections with more than 256 items (" + value + " " + name + ")");
var entry = new XElement("entry");
var keyProp = reflection.Get(item, "Key");
if (keyProp == null)
continue;
WriteObject("Key", keyProp, entry, namespaces);
var propVal = reflection.Get(item, "Value");
if (propVal != null)
{
WriteObject("Value", propVal, entry, namespaces);
}
list.Add(entry);
}
}
else if (value is IEnumerable)
{
XElement list = GetContentWithNamespace(value, namespaces, name);
parent.Add(list);
var itemCount = 0;
foreach (var item in ((IEnumerable)value))
{
if (item == null)
continue;
itemCount += 1;
if (itemCount > MaxNumberOfAllowedItemsInCollection)
throw new UnboundedResultSetException("You cannot send collections with more than 256 items (" + value + " " + name + ")");
WriteObject("value", item, list, namespaces);
}
}
else
{
XElement content = GetContentWithNamespace(value, namespaces, name);
foreach (var property in reflection.GetProperties(value))
{
var propVal = reflection.Get(value, property);
if (propVal == null)
continue;
WriteObject(property, propVal, content, namespaces);
}
content = ApplyMessageSerializationBehaviorIfNecessary(value.GetType(), content);
parent.Add(content);
}
}
示例14: WriteObject
private void WriteObject(string name, object value, XContainer parent, IDictionary<string, XNamespace> namespaces)
{
//TODO custom value converter IValueConverter<T> from RSB
//TODO custom serializer ICustomElementSerializer from RSB
if (ShouldPutAsString(value))
{
var elementName = GetXmlNamespace(namespaces, value.GetType()) + name;
parent.Add(new XElement(elementName, FormatAsString(value)));
}
else if (value is byte[])
{
var elementName = GetXmlNamespace(namespaces, typeof(byte[])) + name;
parent.Add(new XElement(elementName, Convert.ToBase64String((byte[])value)));
}
else if (ShouldTreatAsDictionary(value.GetType()))
{
XElement list = GetContentWithNamespace(value, namespaces, name);
parent.Add(list);
foreach (dynamic keyValuePair in ((IEnumerable)value))
{
var entry = new XElement("entry");
object keyProp = keyValuePair.Key;
if (keyProp == null)
continue;
WriteObject("Key", keyProp, entry, namespaces);
object propVal = keyValuePair.Value;
if (propVal != null)
{
WriteObject("Value", propVal, entry, namespaces);
}
list.Add(entry);
}
}
else if (value is IEnumerable)
{
XElement list = GetContentWithNamespace(value, namespaces, name);
parent.Add(list);
foreach (var item in ((IEnumerable)value))
{
if (item == null)
continue;
WriteObject("value", item, list, namespaces);
}
}
else
{
XElement content = GetContentWithNamespace(value, namespaces, name);
foreach (var property in value.GetType().GetProperties())
{
var propVal = property.GetValue(value, new object[]{});
if (propVal == null)
continue;
WriteObject(property.Name, propVal, content, namespaces);
}
content = ApplyMessageSerializationBehaviorIfNecessary(value.GetType(), content);
parent.Add(content);
}
}
示例15: UpdatePropertyElement
/// <summary>
/// Updates the property element.
/// </summary>
/// <param name="property">The property.</param>
/// <param name="elementPosition">The element position.</param>
/// <param name="fileId">The file id.</param>
private static void UpdatePropertyElement(XContainer property, SourceElementPosition elementPosition, string fileId)
{
if (!property.Elements().Any())
{
var seqpnt = new XElement(
"pt",
new XAttribute("visit", "0"),
new XAttribute("fid", fileId),
new XAttribute("sl", elementPosition.Start));
property.Add(seqpnt);
}
else
{
foreach (var pt in property.Elements().Take(1))
{
pt.Add(new XAttribute("sl", elementPosition.Start));
pt.Add(new XAttribute("fid", fileId));
}
}
}