本文整理汇总了C#中System.Xml.Linq.XContainer类的典型用法代码示例。如果您正苦于以下问题:C# XContainer类的具体用法?C# XContainer怎么用?C# XContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XContainer类属于System.Xml.Linq命名空间,在下文中一共展示了XContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeserializeAll
public static IEnumerable<UserSettings> DeserializeAll(XContainer container)
{
if (container == null)
throw new ArgumentNullException("xml");
return from x in container.Descendants("UserSettings") select Deserialize(x);
}
示例2: DeserializeAll
public static IEnumerable<ClientVersion> DeserializeAll(XContainer container)
{
if (container == null)
throw new ArgumentNullException("container");
return from x in container.Descendants("ClientVersion") select Deserialize(x);
}
示例3: 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);
}
}
}
示例4: ParseParameters
//todo: this can become private when we remove the template rule
public static ImmutableList<RuleParameterValues> ParseParameters(XContainer xml)
{
var builder = ImmutableList.CreateBuilder<RuleParameterValues>();
foreach (var rule in xml.Descendants("Rule").Where(e => e.Elements("Parameters").Any()))
{
var analyzerId = rule.Elements("Key").Single().Value;
var parameterValues = rule
.Elements("Parameters").Single()
.Elements("Parameter")
.Select(e => new RuleParameterValue
{
ParameterKey = e.Elements("Key").Single().Value,
ParameterValue = e.Elements("Value").Single().Value
});
var pvs = new RuleParameterValues
{
RuleId = analyzerId
};
pvs.ParameterValues.AddRange(parameterValues);
builder.Add(pvs);
}
return builder.ToImmutable();
}
示例5: UpdateGeocodes
public void UpdateGeocodes(XContainer result, Org org)
{
if (result == null) throw new ArgumentNullException("result");
var element = result.Element("geometry");
if (element == null) return;
var locationElement = element.Element("location");
if (locationElement == null) return;
var lat = locationElement.Element("lat");
if (lat != null)
{
org.Lat = lat.Value.ToNullableDouble();
org.Modified = DateTime.Now;
}
var lng = locationElement.Element("lng");
if (lng != null)
{
org.Lon = lng.Value.ToNullableDouble();
org.Modified = DateTime.Now;
}
}
示例6: LoadLayout
/// <summary>
/// Loads a structure layout based upon an XML container's children.
/// </summary>
/// <param name="layoutTag">The collection of structure field tags to parse.</param>
/// <returns>The structure layout that was loaded.</returns>
public static StructureLayout LoadLayout(XContainer layoutTag)
{
StructureLayout layout = new StructureLayout();
foreach (XElement element in layoutTag.Elements())
HandleElement(layout, element);
return layout;
}
示例7: ParseIssues
private List<ValidationIssue> ParseIssues(XContainer document, string rootName, string listName, string tagName, Severity severity)
{
var elements = from e in document.Descendants(_namespace + rootName) select e;
var issues = new List<ValidationIssue>();
foreach (var element in elements)
{
foreach (var list in element.Descendants(_namespace + listName))
{
foreach (var errorElement in list.Descendants(_namespace + tagName))
{
var issue = new ValidationIssue { Severity = severity };
if (errorElement.Descendants(_namespace + "line").Any())
issue.Row = int.Parse(errorElement.Descendants(_namespace + "line").First().Value);
if (errorElement.Descendants(_namespace + "col").Any())
issue.Column = int.Parse(errorElement.Descendants(_namespace + "col").First().Value);
if (errorElement.Descendants(_namespace + "message").Any())
{
issue.Title = errorElement.Descendants(_namespace + "message").First().Value;
issue.MessageId = Encoding.UTF8.GetString(MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(issue.Title)));
}
issues.Add(issue);
}
}
}
return issues;
}
示例8: GetGuids
internal static List<string> GetGuids(XContainer owningElement, string propertyName)
{
var propElement = owningElement.Element(propertyName);
return (propElement == null) ? new List<string>() : (from osEl in propElement.Elements(SharedConstants.Objsur)
select osEl.Attribute(SharedConstants.GuidStr).Value.ToLowerInvariant()).ToList();
}
示例9: SetTier2Boxes
private static void SetTier2Boxes(List<DataRow> seats, XContainer root)
{
var boxes = GetChildById(root, "Tier2Boxes");
var left = GetChildById(boxes, "Left").ReorderElements(OrderBy.ChildMinY);
var leftBoxes = new List<Tuple<string, int>>
{
new Tuple<string, int>("A", 56),
new Tuple<string, int>("B", 57),
new Tuple<string, int>("C", 58),
new Tuple<string, int>("D", 59)
};
SetStandardBoxes(seats, left, leftBoxes);
var right = GetChildById(boxes, "Right").ReorderElements(OrderBy.ChildMinY);
var rightBoxes = new List<Tuple<string, int>>
{
new Tuple<string, int>("H", 63),
new Tuple<string, int>("G", 62),
new Tuple<string, int>("F", 61),
new Tuple<string, int>("E", 60)
};
SetStandardBoxes(seats, right, rightBoxes);
}
示例10: TryParse
public static bool TryParse(XContainer xml, out GoodreadsBook result)
{
result = null;
var bookNode = (xml is XElement && (xml as XElement).Name == "best_book") ? xml as XElement : xml.Descendants("best_book").FirstOrDefault();
var idNode = (bookNode.Element("id")?.FirstNode as XText)?.Value;
var titleNode = bookNode.Element("title");
var authorNode = bookNode.Element("author");
var title = titleNode?.Value;
if (string.IsNullOrEmpty(title))
{
return false;
}
int id;
if (idNode == null || !int.TryParse(idNode, out id))
{
id = int.MinValue;
}
GoodreadsAuthor author;
if (authorNode == null || !GoodreadsAuthor.TryParse(authorNode, out author))
{
result = new GoodreadsBook(id, title);
}
else
{
result = new GoodreadsBook(id, title, author);
}
return true;
}
示例11: OrderByMinY
private static void OrderByMinY(XContainer root)
{
var elements = root.Elements().ToList();
elements.ForEach(x => x.Remove());
elements = elements.OrderBy(x => x, new CircleCyComparer()).ToList();
elements.ForEach(root.Add);
}
示例12: ParseErrorsIntoResponse
private static IntacctServiceResponse ParseErrorsIntoResponse(XContainer errorMessage)
{
var response = IntacctServiceResponse.Failed;
response.AddErrors(ParseErrors(errorMessage));
return response;
}
示例13: GetSubmission
private static dynamic GetSubmission(XContainer doc)
{
return (from element in doc.Descendants(Namespaces.XForms + "submission")
let resource = element.Attribute("resource")
where resource != null
select new {Element = element, TargetUri = resource.Value}).FirstOrDefault();
}
示例14: ExtractFeatures
private void ExtractFeatures(XContainer layer)
{
foreach (var feature in layer.Elements())
{
_featureInfo.FeatureInfos.Add(ExtractFeatureElements(feature));
}
}
示例15: WithConfigurationSettings
static void WithConfigurationSettings(XContainer configuration, Action<string, string, XAttribute> roleSettingNameAndValueAttributeCallback)
{
foreach (var roleElement in configuration.Elements()
.SelectMany(e => e.Elements())
.Where(e => e.Name.LocalName == "Role"))
{
var roleNameAttribute = roleElement.Attributes().FirstOrDefault(x => x.Name.LocalName == "name");
if (roleNameAttribute == null)
continue;
var configSettingsElement = roleElement.Elements().FirstOrDefault(e => e.Name.LocalName == "ConfigurationSettings");
if (configSettingsElement == null)
continue;
foreach (var settingElement in configSettingsElement.Elements().Where(e => e.Name.LocalName == "Setting"))
{
var nameAttribute = settingElement.Attributes().FirstOrDefault(x => x.Name.LocalName == "name");
if (nameAttribute == null)
continue;
var valueAttribute = settingElement.Attributes().FirstOrDefault(x => x.Name.LocalName == "value");
if (valueAttribute == null)
continue;
roleSettingNameAndValueAttributeCallback(roleNameAttribute.Value, nameAttribute.Value, valueAttribute);
}
}
}