本文整理匯總了C#中System.Xml.Linq.XContainer.Elements方法的典型用法代碼示例。如果您正苦於以下問題:C# XContainer.Elements方法的具體用法?C# XContainer.Elements怎麽用?C# XContainer.Elements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XContainer
的用法示例。
在下文中一共展示了XContainer.Elements方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: HandleEmployee
private static Employee HandleEmployee(XContainer xml)
{
var m = new Employee
{
Salary = decimal.Parse(xml.Elements("Salary").First().Value),
Person = HandlePerson(xml.Elements("Person").FirstOrDefault())
};
return m;
}
示例2: HandlePerson
private static Person HandlePerson(XContainer xml)
{
var p = new Person
{
Address = xml.Elements("Address").First().Value,
Name = xml.Elements("Name").First().Value
};
return p;
}
示例3: Post
public Post(XContainer post)
{
// Get the string properties from the post's element values
Title = getvalue(post, "title");
Link = getvalue(post, "guid");
Description = getvalue(post, "description");
Creator = getvalue(post, "{http://purl.org/dc/elements/1.1/}creator");
if (post.Elements("{http://purl.org/rss/1.0/modules/content/}encoded").Any())
Content = post.Elements("{http://purl.org/rss/1.0/modules/content/}encoded").First().Value;
else if (post.Elements("enclosure").Any())
if (post.Elements("enclosure").First().Attribute("url") != null)
imageUrl = post.Elements("enclosure").First().Attribute("url").Value;
if (!String.IsNullOrEmpty(Content))
{
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(Content);
var imgLinks = doc.DocumentNode
.Descendants("img")
.Select(n => n.Attributes["src"].Value)
.ToArray();
if (imgLinks.Length > 0)
{
imageUrl = imgLinks[0].ToString();
}
}
/*//Content = getvalue(post, "{http://purl.org/rss/1.0/modules/content/}encoded");
if (post.Elements("{http://purl.org/rss/1.0/modules/content/}encoded").Any())
{
Content = post.Elements("{http://purl.org/rss/1.0/modules/content/}encoded").First().Value;
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(Content);
var imgLinks = doc.DocumentNode
.Descendants("img")
.Select(n => n.Attributes["src"].Value)
.ToArray();
if (imgLinks.Length > 0)
{
imageUrl = imgLinks[0].ToString();
}
}*/
DateTime result;
if (DateTime.TryParse(getvalue(post, "pubDate"), out result))
pubDate = (DateTime?)result;
}
示例4: 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);
}
示例5: GenerateHtmlDocuments
static HtmlDocument[] GenerateHtmlDocuments(XContainer element)
{
if (element == null)
return null;
return element.Elements(DocumentNodeName).Select(GenerateHtmlDocument).ToArray();
}
示例6: ChecksCallsInElement
/// <summary>
/// Checkses the calls in element.
/// </summary>
/// <param name="ie"> The ie. </param>
/// <param name="tc"> The tc. </param>
/// <param name="ic"> The ic. </param>
/// <remarks>
/// </remarks>
private void ChecksCallsInElement(XContainer ie, string tc, string ic) {
foreach (var e in ie.Elements("call").ToArray()) {
var code = e.Id();
if (!Context.Generators.ContainsKey(code)) {
continue;
}
var gen = Context.Generators[code];
if (gen.IsValid) {
gen.Execute(Context, e);
UserLog.Trace("generator " + code + " called in " + tc + "/" + ic + " " + e.Describe().File + ":" +
e.Describe().Line);
}
else {
var message = "try call not valid generator with code " + code + " in " + tc + "/" + ic;
AddError(
ErrorLevel.Warning,
message,
"TW2501",
null, e.Describe().File, e.Describe().Line
);
UserLog.Warn(message);
}
}
}
示例7: GenerateRequest
private static string GenerateRequest(XContainer dynListXml, Timespan timespan)
{
var sb = new StringBuilder();
sb.Append("wda=" + GenerateTimespanString(timespan)+ " and ");
using (var enumerator = dynListXml.Elements().GetEnumerator())
{
if (enumerator.MoveNext())
{
bool isLast;
do
{
var current = enumerator.Current;
isLast = !enumerator.MoveNext();
sb.Append(current.Name + "=" + current.Value);
if (!isLast)
{
sb.Append(" and ");
}
} while (!isLast);
}
}
return sb.ToString();
}
示例8: ParseXml
private void ParseXml(XContainer doc)
{
var checks = from check in doc.Elements("check")
where check.Element("url") != null
select new Check
{
Url = (string)check.Element("url"),
ContentMatches = (from content in check.Elements("content")
where content.Element("positive") != null
select new ContentMatch
{
Match = (string)content.Element("positive"),
Required = true
})
.Union(from content in check.Elements("content")
where content.Element("negative") != null
select new ContentMatch
{
Match = (string)content.Element("negative"),
Required = false
})
.ToList()
};
Checks = checks.ToList();
}
示例9: ExtractFeatures
private void ExtractFeatures(XContainer layer)
{
foreach (var feature in layer.Elements())
{
_featureInfo.FeatureInfos.Add(ExtractFeatureElements(feature));
}
}
示例10: ChoiceParameter
public ChoiceParameter(XContainer document)
: base(document)
{
ParameterType = BuildParameterType.ChoiceParameterDefinition;
Options = document.Elements("choice").Select(a => new NameValuePair(a.Value, a.Value)).ToArray();
}
示例11: GetJoins
private static Dictionary<string, string> GetJoins(XContainer ele)
{
if (ele == null)
return new Dictionary<string, string>();
var ret = ele.Elements().ToDictionary(j => j.Attribute("name").Value, j => j.Value);
return ret;
}
示例12: 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;
}
示例13: 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);
}
}
}
示例14: RSAKey
/// <summary>
/// Initializes a new instance of the <see cref="RSAKey" /> class.
/// </summary>
/// <param name="xml">The xml represention to be loaded.</param>
/// <exception cref="System.ArgumentNullException">xml</exception>
public RSAKey(XContainer xml)
{
if(xml == null)
{
throw new ArgumentNullException("xml");
}
XElement elem;
if((elem = xml.Elements("Private").FirstOrDefault()) != null)
{
Private = elem.Value;
}
if((elem = xml.Elements("Public").FirstOrDefault()) != null)
{
Public = elem.Value;
}
}
示例15: DeleteItems
private static void DeleteItems(XContainer items)
{
foreach (var element in items.Elements())
{
var database = Factory.GetDatabase(element.GetAttributeValue("database"));
var obj = database?.GetItem(element.GetAttributeValue("id"));
obj?.Delete();
}
}