本文整理汇总了C#中System.Xml.Linq.XElement.DescendantNodes方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.DescendantNodes方法的具体用法?C# XElement.DescendantNodes怎么用?C# XElement.DescendantNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.DescendantNodes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Style
public Style(XElement xElement)
{
foreach (XElement descendant in xElement.DescendantNodes())
{
switch (descendant.Name.ToString())
{
case "IconStyle":
this.iconStyle = new IconStyle(descendant);
break;
//case "LabelStyle":
// this.labelStyle = new LabelStyle(descendant);
// break;
//case "LineStyle":
// this.lineStyle = new LineStyle(descendant);
// break;
//case "PolyStyle":
// this.polyStyle = new PolyStyle(descendant);
// break;
//case "BalloonStyle":
// this.balloonStyle = new BalloonStyle(descendant);
// break;
//case "ListStyle":
// this.listStyle = new ListStyle(descendant);
// break;
}
}
}
示例2: ChildNodeNavigation
static void ChildNodeNavigation()
{
var bench = new XElement("bench",
new XElement("toolbox",
new XElement("handtool", "Hammer"),
new XElement("handtool", "Rasp")
),
new XElement("toolbox",
new XElement("handtool", "Saw"),
new XElement("powertool", "Nailgun")
),
new XComment("Be careful with the nailgun")
);
foreach (XNode node in bench.Nodes())
{
Console.WriteLine(node.ToString(SaveOptions.DisableFormatting) + ".");
}
// Retrieving elements
foreach (XElement e in bench.Elements())
{
Console.WriteLine(e.Name + "=" + e.Value);
}
foreach (var tool in bench.Elements("toolbox").Elements("handtool"))
{
Console.WriteLine("tool: {0} = {1}", tool.Name, tool.Value);
}
// query
IEnumerable<string> query =
from toolbox in bench.Elements()
where toolbox.Elements().Any(tool => tool.Value == "Nailgun")
select toolbox.Value;
PrintQueryResult(query);
query =
from toolbox in bench.Elements()
from tool in toolbox.Elements()
where tool.Name == "handtool"
select tool.Value;
PrintQueryResult(query);
// counts
int x = bench.Elements("toolbox").Count();
int y = bench.Elements().Where(e => e.Name == "toolbox").Count();
Console.WriteLine("count1: {0}, count2: {1}", x, y);
// Retrieving descendants
Console.WriteLine(bench.Descendants("handtool").Count());
foreach (XNode node in bench.DescendantNodes())
{
Console.WriteLine(node.ToString(SaveOptions.DisableFormatting));
}
}
示例3: Option
public Option(XElement sourceElement, Service service)
{
Service = service;
_texts = sourceElement
.DescendantNodes()
.OfType<XText>()
.Where(t => !string.IsNullOrWhiteSpace(t.Value))
.Select(t => t.Value.Trim())
.ToList();
}
示例4: DecodeTree
// ======================= Вспомогательные процедуры
public static XElement DecodeTree(XElement tree)
{
// Найдем литералы и сделаем таблицу литералов
int[] literals = tree.DescendantNodes()
.Where(nd => nd.NodeType == System.Xml.XmlNodeType.Text)
.Cast<XText>()
.Where(xt => { int val; return Int32.TryParse(xt.Value, out val); })
.Select(xt => Int32.Parse(xt.Value))
.Distinct()
.ToArray();
var lit_dict = RelationalEngine.GetLiteralsForIds(literals).ToDictionary(li => li.literalid);
return DecTree(tree, lit_dict);
}
示例5: AddBatchMethod
public static XElement AddBatchMethod(XElement batch, string cmd, params object[] batchContent)
{
XElement method = new XElement("Method",
new XAttribute("ID", batch.DescendantNodes().Count() + 1),
new XAttribute("Cmd", cmd));
batch.Add(method);
if (batchContent != null)
{
foreach (var item in batchContent)
{
method.Add(item);
}
}
return method;
}
示例6: FixWhitespace
private void FixWhitespace(XElement xmlElement)
{
foreach (var node in xmlElement.DescendantNodes())
{
XElement el = node as XElement;
if (el != null)
{
FixWhitespace(el);
continue;
}
XText txt = node as XText;
if (txt != null)
{
txt.Value = FixWhitespace(txt.Value);
}
}
}
示例7: Create
public static AmbientColor Create (XElement element, Dictionary<string, Cairo.Color> palette)
{
var result = new AmbientColor ();
foreach (var node in element.DescendantNodes ()) {
if (node.NodeType == System.Xml.XmlNodeType.Element) {
var el = (XElement)node;
switch (el.Name.LocalName) {
case "name":
result.Name = el.Value;
break;
default:
result.Colors.Add (Tuple.Create (el.Name.LocalName, ColorScheme.ParsePaletteColor (palette, el.Value)));
break;
}
}
}
return result;
}
示例8: ExtractFeatureElements
private Dictionary<string, string> ExtractFeatureElements(XElement layerElement)
{
try
{
var feature = new Dictionary<string, string>();
var elements = layerElement.DescendantNodes().OfType<XElement>();
foreach (var element in elements)
{
if (!element.HasElements && !element.Name.LocalName.Equals("coordinates"))
feature.Add(element.Name.LocalName, element.Value);
}
return feature;
}
catch (Exception)
{
throw new ApplicationException("Error creating features");
}
}
示例9: HandleExtendedParameters
public override void HandleExtendedParameters(XElement extendedParameters)
{
foreach (XElement param in extendedParameters.DescendantNodes())
{
if(param.Name == "ParticleSystem")
if (param.Attribute("name") != null)
{
if (!emitters.ContainsKey(param.Attribute("name").Value))
{
if (param.Attribute("active") != null)
{
emitters.Add(param.Attribute("name").Value, bool.Parse(param.Attribute("active").Value));
}
else
{
emitters.Add(param.Attribute("name").Value, true);
}
}
}
}
}
示例10: AllInclusiveValue
private string AllInclusiveValue(XElement ele)
{
bool ignoreNext = false;
return string.Join(" ", ele.DescendantNodes().Select(x =>
{
if (ignoreNext)
{
ignoreNext = false;
return null;
}
if (x is XText) return ((XText) x).Value;
if (x is XElement)
{
var xele = (XElement) x;
if (xele.IsEmpty) return "<" + xele.Name + "/>";
ignoreNext = true;
return "<" + xele.Name + ">" + AllInclusiveValue(xele) + "</" + xele.Name + ">";
}
return null;
}).Where(x => x != null));
}
示例11: processMenuElement
private object processMenuElement(XElement theElement, string theDefault, MenuItemClick delg)
{
if (theElement.Name == Common.MenuItem)
{
MenuItem theItem = new MenuItem();
theItem.Header = theElement.GetAttribute("text");
string action = theElement.GetAttribute(Common.MenuAction);
theItem.Tag = action;
if (action == theDefault)
{
theItem.FontWeight = FontWeights.Bold;
}
theItem.Click += new RoutedEventHandler(delg);
/*
theElement.GetAttribute("clientAction")
if (Common.boolValue(theElement.GetAttribute("checked")))
theItem.Checked = true;
if (theItem.Action == theDefault)
theItem.DefaultItem = true;
*/
return theItem;
}
else if (theElement.Name == Common.ProcessSeparator)
{
Separator s = new Separator();
return s;
}
else//sub menu
{
MenuItem theItem = new MenuItem();
theItem.Header = theElement.Attribute("name").Value;
foreach(XElement child in theElement.DescendantNodes() )
{
theItem.Items.Add(processMenuElement((XElement)child, theDefault, delg));
}
return theItem;
}
}
示例12: WriteXmlDocParameter
static void WriteXmlDocParameter(IXmlDocOutput output, XElement xml)
{
foreach (var elem in xml.DescendantNodes()) {
if (elem is XText)
output.Write(XmlDocRenderer.whitespace.Replace(((XText)elem).Value, " "), TextTokenType.XmlDocSummary);
else if (elem is XElement) {
var xelem = (XElement)elem;
switch (xelem.Name.ToString().ToUpperInvariant()) {
case "SEE":
var cref = xelem.Attribute("cref");
if (cref != null)
output.Write(XmlDocRenderer.GetCref((string)cref), TextTokenType.XmlDocToolTipSeeCref);
var langword = xelem.Attribute("langword");
if (langword != null)
output.Write(((string)langword).Trim(), TextTokenType.XmlDocToolTipSeeLangword);
break;
case "PARAMREF":
var nameAttr = xml.Attribute("name");
if (nameAttr != null)
output.Write(((string)nameAttr).Trim(), TextTokenType.XmlDocToolTipParamRefName);
break;
case "BR":
case "PARA":
output.WriteNewLine();
break;
default:
break;
}
}
else
output.Write(elem.ToString(), TextTokenType.XmlDocSummary);
}
}
示例13: ExpandTemplates
static void ExpandTemplates(XDocument doc, List<XElement> templates)
{
foreach (var inheritMarker in doc.Descendants("inherittemplate").ToList())
{
var name = inheritMarker.Attribute("name").Value;
var replacement = inheritMarker.Attribute("replacement")?.Value;
var template = templates.Single(t => t.Attribute("name").Value == name);
var clonedTemplate = new XElement(template);
if (replacement != null)
{
foreach (var attribute in clonedTemplate.Descendants().Attributes())
{
attribute.Value = attribute.Value.Replace(name, replacement);
}
foreach (var text in clonedTemplate.DescendantNodes().OfType<XText>())
{
text.Value = text.Value.Replace(name, replacement);
}
}
inheritMarker.ReplaceWith(clonedTemplate.Elements());
}
}
示例14: ResolveAssertContent
private static void ResolveAssertContent(XElement xAssert, Assert assert, XmlNamespaceManager nsManager)
{
List<string> diagnostics = new List<string>();
List<bool> diagnosticsIsValueOf = new List<bool>();
XName nameElement = XName.Get("name", Constants.ISONamespace);
XName valueofElement = XName.Get("value-of", Constants.ISONamespace);
StringBuilder sbMessage = new StringBuilder();
foreach (XNode node in xAssert.DescendantNodes())
{
if (!(node is XElement))
{
sbMessage.Append(node.ToString());
}
else
{
XElement xEle = (XElement)node;
// resolve name, value-of
string xpathDiagnostic = null;
if (xEle.Name == nameElement)
{
diagnosticsIsValueOf.Add(false);
xpathDiagnostic = "name()";
XAttribute xPath = xEle.Attribute(XName.Get("path"));
if (xPath != null)
{
xpathDiagnostic = String.Format(String.Format("name({0})", xPath.Value));
}
}
else if (xEle.Name == valueofElement)
{
diagnosticsIsValueOf.Add(true);
xpathDiagnostic = xEle.Attribute(XName.Get("select")).Value;
}
if (xpathDiagnostic != null)
{
// get collection index
int index = diagnostics.IndexOf(xpathDiagnostic);
if (index < 0)
{
diagnostics.Add(xpathDiagnostic);
index = diagnostics.Count - 1;
}
sbMessage.Append("{");
sbMessage.Append(index);
sbMessage.Append("}");
index++;
}
}
}
assert.Message = sbMessage.ToString();
assert.Diagnostics = diagnostics.ToArray();
assert.DiagnosticsIsValueOf = diagnosticsIsValueOf.ToArray();
}
示例15: Create
internal static ChunkStyle Create (XElement element, Dictionary<string, HslColor> palette)
{
var result = new ChunkStyle ();
foreach (var node in element.DescendantNodes ()) {
if (node.NodeType == System.Xml.XmlNodeType.Element) {
var el = (XElement)node;
switch (el.Name.LocalName) {
case "name":
result.Name = el.Value;
break;
case "fore":
result.Foreground = ColorScheme.ParsePaletteColor (palette, el.Value);
break;
case "back":
result.Background = ColorScheme.ParsePaletteColor (palette, el.Value);
break;
case "weight":
Xwt.Drawing.FontWeight weight;
if (!Enum.TryParse<Xwt.Drawing.FontWeight> (el.Value, true, out weight))
throw new InvalidDataException (el.Value + " is no valid text weight values are: " + string.Join (",", Enum.GetNames (typeof(Xwt.Drawing.FontWeight))) );
result.FontWeight = weight;
break;
case "style":
Xwt.Drawing.FontStyle style;
if (!Enum.TryParse<Xwt.Drawing.FontStyle> (el.Value, true, out style))
throw new InvalidDataException (el.Value + " is no valid text weight values are: " + string.Join (",", Enum.GetNames (typeof(Xwt.Drawing.FontStyle))) );
result.FontStyle = style;
break;
default:
throw new InvalidDataException ("Invalid element in text color:" + el.Name);
}
}
}
return result;
}