本文整理汇总了C#中System.Xml.Linq.XElement.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.Descendants方法的具体用法?C# XElement.Descendants怎么用?C# XElement.Descendants使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.Descendants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetValue
private void GetValue(Dictionary<string, TmpTestNodeMethod> resultDictionary, XElement test)
{
try
{
var result = new TmpTestNodeMethod(test.Attribute("name").Value);
result.State = Switch.Into<TestNodeState>()
.From(test.Attribute("result").Value)
.Case("Pass", TestNodeState.Success)
.Case("Skip", TestNodeState.Inactive)
.Case("Fail", TestNodeState.Failure)
.Default(TestNodeState.Inconclusive);
if (result.State != TestNodeState.Success)
{
result.Message = test.Descendants(XName.Get("message", ""))
.Select(d => d.Value).MaySingle().Else("");
result.StackTrace =
test.Descendants(XName.Get("stack-trace", "")).Select(d => d.Value).MaySingle().Else("");
result.Message = result.Message + "\n" + result.StackTrace;
}
resultDictionary.Add(result.Name, result);
}
catch (Exception e)
{
_log.Error("Log file parsing error", e);
}
}
示例2: TypesBuilder
public TypesBuilder(XElement element)
{
Types = new HashSet<Type>();
XAttribute typeAttribute = element.Attribute("type");
if (typeAttribute == null)
{
Types.Add(new Type { TypeKind = TypeKind.Text });
return;
}
IEnumerable<XElement> targets = element.Descendants(Constants.TCM_NAMESPACE + "TargetSchema");
if (targets.Count() > 0)
{
TypeKind typeKind = Util.Parse(element.Descendants(Constants.TCM_NAMESPACE + "linktype").First().Value);
foreach (XElement target in targets)
{
Types.Add(new Type { Name = target.Attribute(Constants.XLINK_NAMESPACE + "title").Value, TypeKind = typeKind });
}
return;
}
XElement embedded = element.Descendants(Constants.TCM_NAMESPACE + "EmbeddedSchema").FirstOrDefault();
if (embedded != null)
{
Types.Add(new Type { Name = embedded.Attribute(Constants.XLINK_NAMESPACE + "title").Value, TypeKind = TypeKind.Embedded });
return;
}
Types.Add(new Type { TypeKind = Util.Parse(typeAttribute.Value) });
}
示例3: UpdateInfo
public UpdateInfo(XElement element)
{
XElement versionElement = element.Descendants().First();
XElement urlElement = element.Descendants().Last();
Version = new Version(versionElement.Value);
Url = urlElement.Value;
}
示例4: GetAfterVersion
/// <summary>
/// Recovers the "after" SrcML from a SrcDiff representation.
/// </summary>
/// <param name="xml">The root element of the SrcDiff XML to filter.</param>
/// <returns>A copy of the input XML, with the diff elements removed, representing the modified file.</returns>
public static XElement GetAfterVersion(XElement xml) {
if(xml == null) { throw new ArgumentNullException("xml"); }
var root = new XElement(xml);
//trim any nodes that were deleted (but keeping any common elements that might be within)
foreach(var deleteElement in root.Descendants(DIFF.Delete).ToList()) {
var commonElements = deleteElement.Descendants(DIFF.Common).ToList();
if(commonElements.Count > 0) {
deleteElement.ReplaceWith(commonElements.SelectMany(ce => ce.Nodes()).ToList());
} else {
deleteElement.Remove();
}
}
//add the nodes that were added
foreach(var addElement in root.Descendants(DIFF.Insert).ToList()) {
addElement.ReplaceWith(addElement.Nodes());
}
//remove the diff tags from any remaining common elements
foreach(var commonElement in root.Descendants(DIFF.Common).ToList()) {
commonElement.ReplaceWith(commonElement.Nodes());
}
return root;
}
示例5: FromXml
public override void FromXml(XElement artistBaseXml)
{
// ReSharper disable PossibleNullReferenceException
string uriString;
if (artistBaseXml.Descendants("image")
.FirstOrDefault(x =>x.Attribute("size").Value == "medium") != null)
{
uriString = artistBaseXml.Descendants("image")
.FirstOrDefault(x => x.Attribute("size").Value == "medium")
.Value;
}
else
{
uriString = artistBaseXml.Descendants("image")
.FirstOrDefault()
.Value;
}
BitmapImage img = null;
if (!string.IsNullOrEmpty(uriString))
img = new BitmapImage(new Uri(uriString));
Name = artistBaseXml.Element("name").Value;
MusicBrainzId = artistBaseXml.Element("mbid").Value;
if (artistBaseXml.Element("match") == null
|| string.IsNullOrEmpty(artistBaseXml.Element("match").Value))
SimilarMatch = 0;
else
SimilarMatch = (int) Math.Round(Convert.ToDouble(artistBaseXml.Element("match").Value), 0);
Url = new Uri(artistBaseXml.Element("url").Value, UriKind.RelativeOrAbsolute);
if (img != null) PictureSmall = img;
// ReSharper restore PossibleNullReferenceException
}
示例6: glass_base
public glass_base(XElement xml)
: base(xml)
{
coreDefaults = new glass_base
{
Translucent = Troolean.True,
DoubleSided = Troolean.False,
FogEnabled = Troolean.True,
NeedsWorldSpaceVertexNormal = Troolean.True,
NeedsWorldEyePos = Troolean.True,
NeedsWorldVertexPos = Troolean.True,
//NEEDS_TANGENT_FRAME = 1,
//NEEDS_PER_PIXEL_SPECULAR_LIGHTING = 1,
NeedsLocalCubeMap = Troolean.True,
//NEEDS_SPECULAR_MASK = 1,
ReceivesShadows = Troolean.True,
//IS_THIN_GLASS = 1,
TextureCoordSources =
{
new TextureCoordSource
{
Alias = "Tex0",
UVStream = 0
}
},
Samplers =
{
new Sampler
{
Alias = "SAMPLER_DiffuseColour",
UsageRGB = Sampler.Usage.DiffuseAlbedo,
sRGBRead = true
},
new Sampler
{
Alias = "SAMPLER_NormalMap",
UsageRGB = Sampler.Usage.TangentSpaceNormals
},
new Sampler
{
Alias = "SAMPLER_SpecMap",
UsageRGB = Sampler.Usage.SpecColour,
UsageAlpha = Sampler.Usage.SpecPower
}
}
};
var diff = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "DiffuseColour").FirstOrDefault();
var norm = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "Normal_Map").FirstOrDefault();
var spec = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "Spec_Map").FirstOrDefault();
var cube = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "EnvironmentCube").FirstOrDefault();
if (diff != null) { diffuse = diff.Attribute("FileName").Value; }
if (norm != null) { normal = norm.Attribute("FileName").Value; }
if (spec != null) { specular = spec.Attribute("FileName").Value; }
if (cube != null) { cubeMap = cube.Attribute("FileName").Value; }
}
示例7: water_base
public water_base(XElement xml)
: base(xml)
{
var diff = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "DiffuseColour").FirstOrDefault();
var nor1 = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "Normal_Map").FirstOrDefault();
var spec = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "Spec_Map").FirstOrDefault();
var nor2 = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "Normal_Map2").FirstOrDefault();
var foam = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "Foam_Map").FirstOrDefault();
var cube = xml.Descendants("Texture").Where(e => e.Attribute("Alias").Value == "EnvironmentCube").FirstOrDefault();
if (diff != null) { diffuse = diff.Attribute("FileName").Value; }
if (nor1 != null) { normal = nor1.Attribute("FileName").Value; }
if (spec != null) { specular = spec.Attribute("FileName").Value; }
if (nor2 != null) { normal2 = nor2.Attribute("FileName").Value; }
if (foam != null) { foamMap = foam.Attribute("FileName").Value; }
if (cube != null) { cubeMap = cube.Attribute("FileName").Value; }
var mind = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "Min_distance").FirstOrDefault();
var maxd = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "Max_distance").FirstOrDefault();
var seaf = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "Sea_Falloff").FirstOrDefault();
var shor = xml.Descendants("Constant").Where(e => e.Attribute("Alias").Value == "shore_factor").FirstOrDefault();
if (mind != null) { minDistance = ReadConstant(mind); }
if (maxd != null) { maxDistance = ReadConstant(maxd); }
if (seaf != null) { seaFalloff = ReadConstant(seaf); }
if (shor != null) { shoreFactor = ReadConstant(shor); }
}
示例8: ESentResolveReferenceLinksConfigDlg
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
/// <param name="currentConfig">The current XML configuration XML fragment</param>
public ESentResolveReferenceLinksConfigDlg(string currentConfig)
{
XElement node;
InitializeComponent();
lnkProjectSite.Links[0].LinkData = "https://GitHub.com/EWSoftware/SHFB";
// Load the current settings. Note that there are multiple configurations (one for each help file
// format). However, the settings will be the same across all of them.
config = XElement.Parse(currentConfig);
node = config.Descendants("msdnContentIdCache").First();
txtContentIdCachePath.Text = node.Attribute("cachePath").Value;
udcContentIdLocalCacheSize.Value = ((int?)node.Attribute("localCacheSize") ?? 2500);
node = config.Descendants("targets").First(d => d.Attribute("id").Value == "FrameworkTargets");
txtFrameworkTargetsCachePath.Text = node.Attribute("cachePath").Value;
udcFrameworkTargetsLocalCacheSize.Value = ((int?)node.Attribute("localCacheSize") ?? 2500);
node = config.Descendants("targets").First(d => d.Attribute("id").Value == "ProjectTargets");
txtProjectTargetsCachePath.Text = (string)node.Attribute("cachePath");
udcProjectTargetsLocalCacheSize.Value = ((int?)node.Attribute("localCacheSize") ?? 2500);
chkEnableLocalCache.Checked = !String.IsNullOrWhiteSpace(txtProjectTargetsCachePath.Text);
}
示例9: GetExercise
private static IExerciseDefinition GetExercise(XElement exerciseXml, IDictionary<string, IConstraint> allConstraints)
{
var exercise = new ExerciseDefinition(exerciseXml.Attribute("name").Value,
new ExerciseTemplate(exerciseXml.Attribute("template").Value));
var numbersXml = from n in exerciseXml.Descendants("numbers").First().Descendants("number")
select n;
foreach (var number in numbersXml)
{
var minValue = int.Parse(number.Attribute("minvalue").Value);
var maxValue = int.Parse(number.Attribute("maxvalue").Value);
var decimals = int.Parse(number.Attribute("decimals").Value);
exercise.AddNumberDefinition(new NumberDefinition("", minValue, maxValue, decimals));
}
var constraintsRoot = exerciseXml.Descendants("constraints").FirstOrDefault();
if (constraintsRoot != null)
{
var constraintsXml = from c in constraintsRoot.Descendants("constraint")
select c;
foreach (var constraint in constraintsXml)
{
var constraintName = constraint.Attribute("type").Value;
exercise.AddConstraint(allConstraints[constraintName]);
}
}
return exercise;
}
示例10: Validate
public List<Error> Validate(XElement doc)
{
XNamespace ns = "http://www.wfmc.org/2008/XPDL2.1";
var activities = from intermediateEvent in doc.Descendants(ns + "IntermediateEvent")
let triggerResultMessageElement = intermediateEvent.Element(ns + "TriggerResultMessage")
let triggerAttribute = intermediateEvent.Attribute("Trigger")
let catchThrowAttribute = triggerResultMessageElement.Attribute("CatchThrow")
let eventElement = intermediateEvent.Parent
where
triggerResultMessageElement != null &&
triggerAttribute != null &&
catchThrowAttribute != null &&
catchThrowAttribute.Value == "THROW" &&
triggerAttribute.Value == "Message" &&
eventElement != null
select eventElement.Parent;
return (from activity in activities
let activityId = activity.Attribute("Id").Value
let messageFlows = (from messageFlow in doc.Descendants(ns + "MessageFlow")
where messageFlow.Attribute("Source").Value == activityId
select messageFlow)
where !messageFlows.Any()
select new Error
{
ElementId = Guid.Parse(activityId),
ElementName = activity.Attribute("Name").Value,
ElementXpath = activity.GetAbsoluteXPath(),
Message = "El elemento viola la regla Style 0123"
}).ToList();
}
示例11: ReportRow
public ReportRow(XElement xml, IEnumerable<ReportColumnDescription> columnDescriptions)
{
_columnDescriptions = columnDescriptions;
Type = xml.Name.ToString();
RowType = "";
RowValue = "";
if (xml.Name == "TextRow")
{
if (xml.Attribute("value") != null)
RowValue = xml.Attribute("value").Value;
Columns = new List<ReportColumn>();
}
else
{
var rowData = xml.Descendants("RowData").FirstOrDefault();
if (rowData != null)
{
RowType = rowData.Attribute("rowType").Value;
RowValue = rowData.Attribute("value").Value;
}
var columns = new List<ReportColumn>();
foreach (var columnXML in xml.Descendants("ColData"))
columns.Add(new ReportColumn(columnXML));
Columns = columns;
}
}
示例12: FailureExpression
public FailureExpression(XElement expressionNode)
{
Location = SourceLocation.FromXElement(expressionNode);
var exprTypeAttr = expressionNode.Attribute("type");
if (exprTypeAttr != null)
{
ExpressionType = exprTypeAttr.Value.Trim();
}
var originalNode = expressionNode.Descendants("Original").FirstOrDefault();
if (originalNode != null)
{
OriginalExpression = originalNode.Value.Trim();
}
var expandedNode = expressionNode.Descendants("Expanded").FirstOrDefault();
if (expandedNode != null)
{
ExpandedExpression = expandedNode.Value.Trim();
}
var ExceptionNode = expressionNode.Descendants("Exception").FirstOrDefault();
if (ExceptionNode != null)
{
ExceptionMessage = ExceptionNode.Value.Trim();
}
}
示例13: CreateTrigger
/// <summary>
/// The method for creating a trigger
/// </summary>
/// <param name="_trigger">The xml element containing the trigger description (Root node = Trigger)</param>
/// <returns>The newly created trigger.</returns>
public override Trigger CreateTrigger(XElement _trigger)
{
String id = _trigger.Attribute("id").Value;
String question = _trigger.Descendants("Question").First().Value;
String answer = _trigger.Descendants("Answer").First().Value;
QuestionAnswerTrigger t = new QuestionAnswerTrigger(id, question, answer);
t.preTriggerObjectIds = new List<string>();
t.postTriggerObjectIds = new List<string>();
if (_trigger.Element("PreTriggerObject") != null)
foreach (XElement objectIdElement in _trigger.Element("PreTriggerObject").Elements())
{
t.preTriggerObjectIds.Add(objectIdElement.Value);
}
if (_trigger.Element("PostTriggerObject") != null)
foreach (XElement objectIdElement in _trigger.Element("PostTriggerObject").Elements())
{
t.postTriggerObjectIds.Add(objectIdElement.Value);
}
return t;
}
示例14: Deserialize
public static Playlist Deserialize(XElement xml)
{
Playlist playlist = null;
Guid id;
var idElement = xml.Descendants("Id").FirstOrDefault();
var nameElement = xml.Descendants("Name").FirstOrDefault();
var tracksElement = xml.Descendants("Tracks").FirstOrDefault();
if (null != nameElement &&
null != idElement &&
Guid.TryParse(idElement.Value, out id) &&
null != tracksElement)
{
playlist = new Playlist()
{
Name = nameElement.Value,
Id = id
};
foreach(var trackElement in tracksElement.Descendants("Track"))
{
playlist.Tracks.Add(Track.Deserialize(trackElement));
}
}
else
{
Debug.WriteLine("Playlist: Invalid track XML");
}
return playlist;
}
示例15: ParsePolygon
private Polygon ParsePolygon(string name, XElement pg, string ns, bool onlyOuter)
{
PolygonReader polyReader = new PolygonReader();
var outerBoundary = pg.Descendants(XName.Get("outerBoundaryIs", ns)).FirstOrDefault();
var innerPolygons = pg.Descendants(XName.Get("innerBoundaryIs", ns)).ToList();
if (outerBoundary == null)
{
//check if the linear ring has been added without outer/inner boundaries
var linearRing = pg.Descendants(XName.Get("LinearRing", ns)).FirstOrDefault();
if (linearRing != null)
{
return polyReader.FromPointList(name, linearRing.Descendants(XName.Get("coordinates", ns)).First().Value);
}
return null;
}
Polygon p = polyReader.FromPointList(name, outerBoundary.Descendants(XName.Get("coordinates", ns)).First().Value);
if (!onlyOuter) {
foreach (var innerPolygon in innerPolygons)
{
var linearRings = innerPolygon.Descendants(XName.Get("LinearRing", ns)).ToList();
foreach (var ring in linearRings)
{
p.InnerPolygons.Add(polyReader.FromPointList(name, ring.Descendants(XName.Get("coordinates", ns)).First().Value));
}
}
}
return p;
}