本文整理汇总了C#中System.Xml.Linq.XDocument.Descendants方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.Descendants方法的具体用法?C# XDocument.Descendants怎么用?C# XDocument.Descendants使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.Descendants方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseFeature
/// <summary>
/// Instead of logging on feature per control, I do 1 feature per control type along with the number of occurrences
/// </summary>
/// <param name="document"></param>
/// <returns></returns>
public static IEnumerable<InfoPathFeature> ParseFeature(XDocument document)
{
PublishUrl pubRule = new PublishUrl();
IEnumerable<XElement> allElements = document.Descendants(xsf3Namespace + baseUrl);
// collect the control counts
foreach (XElement element in allElements)
{
if (pubRule.RelativeBase != null) throw new ArgumentException("Should only see one xsf3:baseUrl node");
XAttribute pathAttribute = element.Attribute(relativeUrlBaseAttribute);
if (pathAttribute != null) // this attribute is technically optional per xsf3 spec
{
pubRule.RelativeBase = pathAttribute.Value;
}
}
allElements = document.Descendants(xsfNamespace + xDocumentClass);
foreach (XElement element in allElements)
{
if (pubRule.Publish != null) throw new ArgumentException("Should only see one xsf:xDocumentClass node");
XAttribute pubUrl = element.Attribute(publishUrlAttribute);
if (pubUrl != null)
{
pubRule.Publish = pubUrl.Value;
}
}
yield return pubRule;
// nothing left
yield break;
}
示例2: Parse
public IEnumerable<Issue> Parse(XDocument report)
{
var issuesType = report.Descendants("IssueType");
foreach (var project in report.Descendants("Project"))
{
foreach (var issue in project.Descendants("Issue"))
{
var issueType = GetIssueType(issuesType, issue.Attribute("TypeId").Value);
var sourceFilePath = issue.Attribute("File").Value;
var offsetAttribute = issue.Attribute("Offset");
var lineNumber = GetLine(issue.Attribute("Line"), offsetAttribute != null);
yield return new Issue
{
Project = project.Attribute("Name").Value,
Category = issueType.Attribute("Category").Value,
Description = issueType.Attribute("Description").Value,
FilePath = sourceFilePath,
HelpUri = GetUri(issueType.Attribute("WikiUrl")),
Line = lineNumber,
Message = issue.Attribute("Message").Value,
Name = issue.Attribute("TypeId").Value,
Severity = GetSeverity(issueType.Attribute("Severity")),
Offset = GetOffset(offsetAttribute, sourceFilePath, lineNumber),
Source = Name,
};
}
}
}
示例3: GetObjectXML
public override void GetObjectXML(XDocument sourceDoc)
{
XElement eng;
if (sourceDoc.Descendants("enginePart").Where(f => f.Attribute("name").Value == this.Name).Count() > 0)
{
// Update Existing
eng = sourceDoc.Descendants("enginePart").First(f => f.Attribute("name").Value == this.Name);
eng.Element("MaxHP").Value = this.HP.Max.ToString();
if (eng.Element("Mass") != null)
eng.Element("Mass").Value = this._mass.ToString();
else
eng.Add(new XElement("Mass", this._mass.ToString()));
eng.Element("Thrust").Value = this._thrust.ToString();
addActions(eng.Element("Actions"));
}
else
{
// Create New
XElement actions = new XElement("Actions");
addActions(actions);
eng =
new XElement("enginePart", new XAttribute("name", this.Name),
new XElement("MaxHP", this.HP.Max.ToString()),
new XElement("Mass",this.Mass.ToString()),
new XElement("Thrust", this._thrust.ToString()),
actions);
sourceDoc.Descendants("engineParts").First().Add(eng);
}
}
示例4: GetObjectXML
public override void GetObjectXML(XDocument sourceDoc)
{
XElement act;
if (sourceDoc.Descendants("actionPart").Where(f => f.Attribute("name").Value == this.Name).Count() > 0)
{
// Update Existing
act = sourceDoc.Descendants("actionPart").First(f => f.Attribute("name").Value == this.Name);
act.Element("MaxHP").Value = this.HP.Max.ToString();
if (act.Element("Mass") != null)
act.Element("Mass").Value = this._mass.ToString();
else
act.Add(new XElement("Mass", this._mass.ToString()));
act.Element("ActionDescription").Value = this._actionDescription.ToString();
addActions(act.Element("Actions"));
}
else
{
// Create New
XElement actions = new XElement("Actions");
addActions(actions);
act =
new XElement("actionPart", new XAttribute("name", this.Name),
new XElement("MaxHP", this.HP.Max.ToString()),
new XElement("Mass",this.Mass.ToString()),
new XElement("ActionDescription", this._actionDescription.ToString()),
actions);
sourceDoc.Descendants("actionParts").First().Add(act);
}
}
示例5: TVDBSeries
public TVDBSeries(XDocument xml)
{
Xml = xml;
var series = xml.Descendants("Series").Single();
ID = series.GetInt("id").Value;
Actors = series.Split("Actors");
AirsDay = series.GetEnum<DayOfWeek>("Airs_DayOfWeek");
AirsTime = series.GetDateTime("Airs_Time");
ContentRating = series.Get("ContentRating");
FirstAired = series.GetDateTime("FirstAired");
Genres = series.Split("Genre");
IMDbID = series.Get("IMDB_ID");
Language = series.Get("Language");
Network = series.Get("Network");
Overview = series.Get("Overview");
Rating = series.GetDouble("Rating");
LengthMinutes = series.GetDouble("Runtime");
TvDotComID = series.Get("SeriesID");
Name = series.Get("SeriesName");
Status = series.Get("Status");
BannerPath = series.Get("banner");
FanartPath = series.Get("fanart");
LastUpdated = series.GetUnixDateTime("lastupdated");
PosterPath = series.Get("poster");
Zap2ItID = series.Get("zap2it_id");
Episodes = (
from ep in xml.Descendants("Episode")
where ep.HasElements
select new TVDBEpisode(ep)
)
.ToList();
}
示例6: getFromClause
public static FromClause getFromClause(XDocument xmlDoc)
{
List<string> tableSourceList = new List<string>();
List<string> schemaNameList = new List<string>();
List<string> tableAliasList = new List<string>();
IEnumerable<XAttribute> ts = from t in xmlDoc.Descendants("SqlFromClause").Descendants("SqlTableRefExpression").Attributes("ObjectIdentifier") select t;
foreach (var t in ts)
{
tableSourceList.Add(t.Value);
}
IEnumerable<XAttribute> tsch = from t in xmlDoc.Descendants("SqlFromClause").Descendants("SqlObjectIdentifier").Attributes("SchemaName") select t;
foreach (var s in tsch)
{
schemaNameList.Add(s.Value);
}
IEnumerable<XAttribute> tali = from t in xmlDoc.Descendants("SqlFromClause").Descendants("SqlObjectIdentifier").Attributes("ObjectName") select t;
foreach (var ta in tali)
{
tableAliasList.Add(ta.Value);
}
FromClause newFromClause = new FromClause(tableSourceList, schemaNameList, tableAliasList);
return newFromClause;
}
示例7: Parse
public IEnumerable<Issue> Parse(XDocument report)
{
var issues = new List<Issue>();
var issuesType = report.Descendants("IssueType");
foreach (var project in report.Descendants("Project"))
{
foreach (var issue in project.Descendants("Issue"))
{
var issueType = GetIssueType(issuesType, issue.Attribute("TypeId").Value);
issues.Add(new Issue
{
Project = project.Attribute("Name").Value,
Category = issueType.Attribute("Category").Value,
Description = issueType.Attribute("Description").Value,
FilePath = issue.Attribute("File").Value,
HelpUri = GetUri(issueType.Attribute("WikiUrl")),
Line = GetLine(issue.Attribute("Line")),
Message = issue.Attribute("Message").Value,
Name = issue.Attribute("TypeId").Value,
Severity = GetSeverity(issueType.Attribute("Severity")),
Offset = GetOffset(issue.Attribute("Offset")),
Source = Name,
});
}
}
return issues;
}
示例8: SettingsPage
public SettingsPage()
{
InitializeComponent();
#if !DEBUG
_xmlDoc = string.IsNullOrEmpty(_settings.XmlThemes) ? XDocument.Load("Themes.xml") : XDocument.Parse(_settings.XmlThemes);
#else
_xmlDoc = XDocument.Load("Themes.xml");
#endif
if (_xmlDoc != null)
{
if (string.IsNullOrEmpty(_settings.XmlThemes)) _settings.XmlThemes = _xmlDoc.ToString();
_themeNames = _xmlDoc.Descendants("theme").Attributes("name").Select(a => a.Value).ToList();
ThemeList.ItemsSource = _themeNames;
ThemeList.SelectedItem = _startTheme = _settings.ThemeName;
ThemeList.SelectionChanged += (_, __) =>
{
string name = ThemeList.SelectedItem as string;
if (!string.IsNullOrEmpty(name) && _xmlDoc != null && name != _settings.ThemeName)
{
_settings.ThemeName = name;
var node = _xmlDoc.Descendants("theme").Where(d => d.Attribute("name").Value == name).FirstOrDefault();
if (node != null) _settings.Theme = node.ToString();
}
};
}
bytesUsed.Text = string.Format("Used space: {0}", GetStoreUsedSize().ToSize());
}
示例9: RetrieveStyleElement
/// <summary>
/// Retrieves the Style element. This can either be the Style element contained in <paramref name="element"/> or a styleUrl element contained in <paramref name="element"/>.
/// </summary>
/// <param name="element">The element that contains the Style element or the styleUrl.</param>
/// <param name="doc">The kml document.</param>
/// <param name="docNamespace">The namespace of the kml document.</param>
/// <returns></returns>
public static XElement RetrieveStyleElement(XElement element, XDocument doc, XNamespace docNamespace)
{
XElement styleUrl = element.Element(docNamespace + "styleUrl");
if (styleUrl != null)
{
string value = styleUrl.Value.Trim();
if (value.StartsWith("#"))
{
value = value.Substring(1);
var referredStyle = doc.Descendants().Where(o => o.Name == docNamespace + "Style").Where(o => (string)o.Attribute("id") == value).FirstOrDefault();
if (referredStyle != null)
{
return referredStyle;
}
else
{
referredStyle = doc.Descendants().Where(o => o.Name == docNamespace + "StyleMap").Where(o => (string)o.Attribute("id") == value).FirstOrDefault();
if (referredStyle != null)
{
styleUrl = referredStyle.Elements(docNamespace + "Pair").Where(o => o.Element(docNamespace + "key").Value == "normal").FirstOrDefault();
return RetrieveStyleElement(styleUrl, doc, docNamespace);
}
}
}
}
return null;
}
示例10: Buscar
public List<MedDAL.DAL.bitacora> Buscar(XDocument xmlDoc, int iFiltro, string sCadena)
{
switch (iFiltro)
{
case 1:
var oQuery = from c in xmlDoc.Descendants("bitacora")
where (c.Element("Usuario").Value.ToString().ToUpper().Contains(sCadena.ToUpper()))
where (c.Element("Modulo").Value.ToString().ToUpper().Contains(sCadena.ToUpper()))
select c;
List<MedDAL.DAL.bitacora> lstBitacora = ObtenerBitacoraQuery(oQuery);
return lstBitacora;
case 2:
oQuery = from c in xmlDoc.Descendants("bitacora")
where (c.Element("Usuario").Value.ToString().ToUpper().Contains(sCadena.ToUpper()))
select c;
lstBitacora = ObtenerBitacoraQuery(oQuery);
return lstBitacora;
case 3:
oQuery = from c in xmlDoc.Descendants("bitacora")
where (c.Element("Modulo").Value.ToString().ToUpper().Contains(sCadena.ToUpper()))
select c;
lstBitacora = ObtenerBitacoraQuery(oQuery);
return lstBitacora;
default:
return null;
}
}
示例11: XmlReviewRepository
public XmlReviewRepository()
{
_dbPath = HttpContext.Current.Server.MapPath ("~/App_LocalResources/Data.xml");
_database = XDocument.Load (_dbPath);
var data = _database
.Descendants ("review")
.Select (review => new Review () {
Id = Int32.Parse(review.Element ("id").Value),
PostId = Int32.Parse(review.Element ("postid").Value),
Title = review.Element ("title").Value,
Description = review.Element ("description").Value,
Date = review.Element ("date").Value,
CommunityUrl = review.Element ("communityurl").Value,
CommunutyDiscussionsCount = (Int32.Parse(review.Element ("communutydiscussionscount").Value)),
Author = review.Element ("author").Value,
AuthorId = review.Element ("authorid").Value,
Tags = review.Element ("tags").Value.Split(',')
})
.OrderByDescending(review => review.Id)
.AsQueryable ();
Reviews = data;
Tags = _database
.Descendants ("tags")
.SelectMany (element => element.Value.Split(','))
.Distinct ()
.AsQueryable ();
}
示例12: Modify
public XDocument Modify(XDocument document)
{
var elementsWithHref = document.Descendants()
.Where(e => e.Name.LocalName == "a" || e.Name.LocalName == "link");
var elementsWithSrc = document.Descendants()
.Where(e => e.Name.LocalName == "img" || e.Name.LocalName == "script");
var formElementsWithAction = document.Descendants()
.Where(e => e.Name.LocalName == "form");
var root = HttpRequest.ApplicationPath.TrimEnd('/');
foreach (var element in elementsWithHref)
{
ExpandUrl(element, "href", root);
}
foreach (var element in elementsWithSrc)
{
ExpandUrl(element, "src", root);
}
foreach (var element in formElementsWithAction)
{
ExpandUrl(element, "action", root);
}
return document;
}
示例13: ParseDocument
public static SettingsBase ParseDocument(XDocument document)
{
SettingsBase settings = new SettingsBase();
foreach (XElement element in document.Descendants("Parameter"))
{
Parameter parameter = new Parameter()
{
Name = element.Attribute("Name").GetValue(),
Value = element.Attribute("Value").GetValue()
};
settings.Parameters.Add(parameter);
}
foreach (XElement element in document.Descendants("DataSource"))
{
Source source = new Source();
source.Name = element.Attribute("Name").GetValue();
source.Url = element.Attribute("Url").GetValueAsUri();
TimeSpan? interval = element.Attribute("Interval").GetValueAsTimeSpan();
source.Interval = interval == null ? TimeSpan.MaxValue : interval.Value;
settings.DataSources.Add(source);
}
return settings;
}
示例14: GetClassNamesLettersList
public static bool GetClassNamesLettersList(XDocument Students, out List<string> ClassList, out List<char> Letters, out List<string[]> Names)
{
Letters = new List<char>();
ClassList = new List<string>();
Names = new List<string[]>();
if (Students != null)
foreach (string Validator in Students.Descendants("ValidStuds")) //Проверка на валидность файла списка студентов
if (Validator == "545k#cOFj$qM2LbnEY")
{
foreach (string Class in Students.Descendants("name"))
ClassList.Add(Class);
foreach (string Letter in Students.Descendants("let"))
if (Letter != "")
Letters.Add(Letter[0]);
else
Letters.Add(' ');
foreach (string NameList in Students.Descendants("n"))
Names.Add(Splitter(NameList));
return true; //Если не пустой документ, то возвращает труЪ
}
return false;
}
示例15: UpdateVs2010Compatibility
void UpdateVs2010Compatibility(XDocument document, string file) {
var elements = document.Descendants().Where(element
=> element.Name.LocalName == "VSToolsPath" || element.Name.LocalName == "VisualStudioVersion" );
var xElements = elements as XElement[] ?? elements.ToArray();
bool save=xElements.Any();
xElements.Remove();
elements=document.Descendants().Where(element
=> element.Name.LocalName == "Import" &&
(element.Attribute("Project").Value.StartsWith("$(MSBuildExtensionsPath)")||
element.Attribute("Project").Value.StartsWith("$(MSBuildExtensionsPath32)")));
var enumerable = elements as XElement[] ?? elements.ToArray();
if (!save)
save = enumerable.Any();
if (IsWeb(document, GetOutputType(document))&& !document.Descendants().Any(element =>
element.Name.LocalName == "Import" && element.Attribute("Project").Value.StartsWith("$(VSToolsPath)")&&
element.Attribute("Condition").Value.StartsWith("'$(VSToolsPath)' != ''"))) {
var element = new XElement(_xNamespace+"Import");
element.SetAttributeValue("Project",@"$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets");
element.SetAttributeValue("Condition", @"'$(VSToolsPath)' != ''");
Debug.Assert(document.Root != null, "document.Root != null");
document.Root.Add(element);
save = true;
}
enumerable.Remove();
if (save)
DocumentHelper.Save(document, file);
}