本文整理汇总了C#中System.Xml.Linq.XDocument.Elements方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.Elements方法的具体用法?C# XDocument.Elements怎么用?C# XDocument.Elements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.Elements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetReferences
private static IEnumerable<ReferenceDescriptor> GetReferences(XDocument document) {
var assemblyReferences = document
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("Reference"))
.Where(c => c.Attribute("Include") != null)
.Select(c => {
string path = null;
XElement attribute = c.Elements(ns("HintPath")).FirstOrDefault();
if (attribute != null) {
path = attribute.Value;
}
return new ReferenceDescriptor {
SimpleName = ExtractAssemblyName(c.Attribute("Include").Value),
FullName = c.Attribute("Include").Value,
Path = path,
ReferenceType = ReferenceType.Library
};
});
var projectReferences = document
.Elements(ns("Project"))
.Elements(ns("ItemGroup"))
.Elements(ns("ProjectReference"))
.Attributes("Include")
.Select(c => new ReferenceDescriptor {
SimpleName = Path.GetFileNameWithoutExtension(c.Value),
FullName = Path.GetFileNameWithoutExtension(c.Value),
Path = c.Value,
ReferenceType = ReferenceType.Project
});
return assemblyReferences.Union(projectReferences);
}
示例2: ParseDocument
public XDocument ParseDocument(string text)
{
//System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew();
XDocument doc = new XDocument();
try
{
StringCounter sc = new StringCounter(text);
sc.TrimStart();
if (sc.StartsWith("<"))
{
while (!sc.IsAtEnd)
{
XContainer childNode = this.ParseNode(sc, doc);
}
XElement[] enm = MyHelper.EnumToArray(doc.Elements());
if (enm.Length > 1)
{
XElement root = new XElement(XName.Get("root"));
foreach (XElement elem in enm)
{
root.Add(elem);
}
doc.Elements().Remove();
doc.Add(root);
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
}
//sw.Stop();
//System.Diagnostics.Debug.WriteLine(sw.Elapsed.TotalMilliseconds.ToString("N0"));
return doc;
}
示例3: ExtractResult
public OstcOrderResult ExtractResult(Uri responseUri, XDocument responsePage)
{
var statusImageXml = responsePage
.Elements("html")
.Elements("body")
.Elements("form")
.Elements("table")
.Elements("tr")
.Elements("td").Where(x => x.Attributes("class").Any(y => y.Value== "sidebarFooter"))
.Elements("img")
.FirstOrDefault();
if (statusImageXml == null)
statusImageXml = responsePage
.Elements("html")
.Elements("body")
.Elements("blockquote")
.Elements("img")
.FirstOrDefault();
if (statusImageXml == null)
return null;
var statusImageSrc = statusImageXml.Attributes("src").Select(x => x.Value).FirstOrDefault();
switch (System.IO.Path.GetFileNameWithoutExtension(statusImageSrc))
{
case "ampel_gruen":
break;
case "ampel_gelb":
return new OstcOrderResult() { Status = OstcOrderStatus.Processing };
default:
return new OstcOrderResult() { Status = OstcOrderStatus.Failed, Message = statusImageXml.Value };
}
var certLinkXml = statusImageXml
.Elements("p")
.Elements("a")
.FirstOrDefault();
if (certLinkXml == null)
{
// Darf eigentlich nicht passieren...
return new OstcOrderResult()
{
Status = OstcOrderStatus.Unknown
};
}
var hrefAttr = certLinkXml.Attribute("href");
if (hrefAttr == null)
{
// Darf eigentlich nicht passieren...
return new OstcOrderResult()
{
Status = OstcOrderStatus.Unknown
};
}
var certUri = new Uri(responseUri, hrefAttr.Value);
return new OstcOrderResult { Status = OstcOrderStatus.Successful, DownloadUrl = certUri };
}
示例4: Configuration
/// <summary>
/// 初始化配置文件
/// </summary>
private Configuration()
{
if (File.Exists(FILE_NAME))
{
try
{
document = System.Xml.Linq.XDocument.Load(FILE_NAME);
foreach (var elem in document.Elements("properties"))
{
if (elem.Name == "comment")
comment = elem.Value;
if (elem.Name == "entry" && elem.Attributes("key") != null)
{
if (elem.Attributes("key").First().Value == "ext_dict")
extDicStr = elem.Value;
if (elem.Attributes("key").First().Value == "ext_stopwords")
extStopStr = elem.Value;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.StackTrace);
}
}
}
示例5: populateLookup
/**
* @name populateLookup
*
* @desc
*
* @param xml - IN -
* @return None
*/
private void populateLookup(XDocument xml)//XDocument xml
{
IEnumerable<XElement> elements = null;
if (xml.Element("TACTICALGRAPHICS").HasElements) //"SINGLEPOINTMAPPINGS"
{
elements = xml.Elements();
IEnumerator<XElement> itr = null;// = xml.DescendantNodes().GetEnumerator();
//XElement unitConstants = XElement.Load(ofd1.FileName, LoadOptions.None);
itr = elements.GetEnumerator();
XElement child = null;
itr.MoveNext();
child = itr.Current;//TACTICALGRAPHICS
if (child.HasElements)
{
elements = child.Elements();
itr = elements.GetEnumerator();//SYMBOL
while (itr.MoveNext())
{
child = itr.Current; /*SymbolDef .XNodeToSymbolDef*/
TacticalGraphicLookupInfo temp = TacticalGraphicLookupInfo.XNodeToTGLookupInfo(child);// SPSymbolDef temp = SPSymbolDef.XNodeToSPSymbolDef(child);
if ((temp != null) && _TGLookup.ContainsKey(temp.getBasicSymbolID()) == false)//temp will be null if node is an XCOMMENT
_TGLookup[temp.getBasicSymbolID()] = temp.getMapping();
}//end while
}
}//end if
}
示例6: CollectLimitsTo
private List<YaLimits> CollectLimitsTo(XDocument xDocument)
{
//Лист структур YaSearchResult, который метод в итоге возвращает.
List<YaLimits> ret = new List<YaLimits>();
//из полученного XML'я выдираем все элементы с именем "time-interval" - это результаты поиска
var groupQuery = from gr in xDocument.Elements().
Elements("response").
Elements("limits").
Elements("time-interval")
select gr;
//DateTime dtFrom, dtTo;
//каждый элемент group преобразовывается в объект SearchResult
for (int i = 0; i < groupQuery.Count(); i++)
{
string strFrom = GetAttribute(groupQuery.ElementAt(i), "from");
string strTo = GetAttribute(groupQuery.ElementAt(i), "to");
//string strTo = GetValue(groupQuery.ElementAt(i), "time-interval");
string iQuantity = GetValue(groupQuery.ElementAt(i), "");
//string indexedTimeQuery = GetValue(groupQuery.ElementAt(i), "modtime");
//string cacheUrlQuery = GetValue(groupQuery.ElementAt(i), "saved-copy-url");
ret.Add(new YaLimits(strFrom, strTo, iQuantity));
}
return ret;
}
示例7: GetValues
public List<MyFitnessXML> GetValues(XDocument xDoc)
{
var Chart_DataL = from c in xDoc.Elements("chart").Elements("chart_data").Elements("row")
select c;
var Chart_DataStrings = from c in Chart_DataL
where c.Element("string") != null
select c.Elements("string");
var Chart_DataNumbers = from c in Chart_DataL
where c.Element("number") != null
select c.Elements("number");
List<MyFitnessXML> XMLList = new List<MyFitnessXML>();
//Start at 1 to avoid first record is 0 bug
for (int i = 1; i < Chart_DataStrings.ElementAt(0).Count(); i++)
{
XMLList.Add(new MyFitnessXML
{
StringValue = (string)Chart_DataStrings.ElementAt(0).ElementAt(i),
NumberValue = (double)Chart_DataNumbers.ElementAt(0).ElementAt(i)
});
}
return XMLList;
}
示例8: ParseXmlDocument
private static TemplateInformation ParseXmlDocument(XDocument document)
{
var templateInformation = new TemplateInformation();
var template = (from x in document.Elements("template") select x).FirstOrDefault();
return ReadXmlDocument(templateInformation, template);
}
示例9: FromXml
public static Configuration FromXml(XDocument xdoc)
{
var result = new Dictionary<string, string>();
foreach (var param in xdoc.Elements("configuration").SelectMany(i => i.Elements("parameter")))
{
var keyAttr = param.Attribute("key");
var valueAttr = param.Attribute("value");
if (keyAttr == null)
{
throw new ArgumentException("Attribute 'key' is required for element 'parameter'.");
}
string parameterValue = null;
if (valueAttr != null)
{
parameterValue = valueAttr.Value;
}
else if (param.Elements().Any())
{
parameterValue = param.Elements().Aggregate("", (xmlText, el) => xmlText + el.ToString());
}
result.Add(keyAttr.Value, parameterValue);
}
return new Configuration(result);
}
示例10: IsSatisfiedByInternal
protected override ConventionResult IsSatisfiedByInternal(string assemblyName, XDocument projectDocument)
{
var references =
projectDocument.Elements()
.Single(x => x.Name.LocalName == "Project")
.Elements()
.Where(x => x.Name.LocalName == "ItemGroup")
.SelectMany(x => x.Elements().Where(e => e.Name.LocalName == "Reference"));
var failures =
references
.Where(x => x.Elements().Any(e => e.Name.LocalName == "HintPath" && Regex.IsMatch(e.Value, ObjOrBinPattern)))
.Select(x =>
new Failure(
x.Attributes().Single(a => a.Name.LocalName == "Include").Value,
x.Elements().Single(e => e.Name.LocalName == "HintPath").Value))
.ToArray();
if (failures.Any())
{
var failureText =
FailureMessage.FormatWith(assemblyName) +
Environment.NewLine +
failures.Aggregate(string.Empty,
(s, t) => s + "\t" + t.Reference + " " + "(" + t.Location + ")" + Environment.NewLine);
return ConventionResult.NotSatisfied(assemblyName, failureText);
}
return ConventionResult.Satisfied(assemblyName);
}
示例11: ParseEnglishGetCapabilities
public Dictionary<string, Dictionary<string, string>> ParseEnglishGetCapabilities(XDocument getCapabilitiesEnglish)
{
Dictionary<string, Dictionary<string, string>> englishData = new Dictionary<string, Dictionary<string, string>>();
IEnumerable<XElement> englishLayers =
from el in getCapabilitiesEnglish.Elements(WMS + "WMS_Capabilities").Elements(WMS + "Capability").Elements(WMS + "Layer").Elements(WMS + "Layer")
select el;
if (englishLayers != null)
{
foreach (var layer in englishLayers)
{
var nameElement = layer.Element(WMS + "Name");
string name = nameElement != null ? nameElement.Value : null;
var titleElement = layer.Element(WMS + "Title");
string title = titleElement != null ? titleElement.Value : null;
var abstractElement = layer.Element(WMS + "Abstract");
string @abstract = abstractElement != null ? abstractElement.Value : null;
var values = new Dictionary<string, string>();
values.Add("title", title);
values.Add("abstract", @abstract);
englishData.Add(name, values);
}
}
return englishData;
}
示例12: populateLookup
private void populateLookup(XDocument xml)
{
IEnumerable<XElement> elements = null;
if (xml.Element("UNITCONSTANTS").HasElements)
{
elements = xml.Elements();
IEnumerator<XElement> itr = null;// = xml.DescendantNodes().GetEnumerator();
//XElement unitConstants = XElement.Load(ofd1.FileName, LoadOptions.None);
itr = elements.GetEnumerator();
XElement child = null;
itr.MoveNext();
child = itr.Current;//UNITCONSTANTS
if (child.HasElements)
{
elements = child.Elements();
itr = elements.GetEnumerator();//SYMBOLS
while (itr.MoveNext())
{
child = itr.Current;
UnitDef temp = UnitDef.XNodeToUnitDef(child);
if ((temp != null) && _UnitDefinitions.ContainsKey(temp.getBasicSymbolId())==false)//temp will be null if node is an XCOMMENT
_UnitDefinitions.Add(temp.getBasicSymbolId(), temp);
}//end while
}
}//end if
}//end populate lookup
示例13: DrumLoad
private static IEnumerable<DrumPreset> DrumLoad(XDocument document)
{
var preset = document.Elements("ux").Select(e => e.Elements("preset")).Select(e => e.Elements("drum")).FirstOrDefault();
if (preset == null)
throw new ArgumentException();
var notes = preset.Elements("note");
foreach (var note in notes)
{
var number = note.GetAttribute(PresetReader.xnumber);
var note_number = note.GetAttribute(PresetReader.xnote);
int num = 0, note_num = 0;
if (!int.TryParse(number, out num))
throw new ArgumentException();
if (!int.TryParse(note_number, out note_num))
throw new ArgumentException();
yield return new DrumPreset(num, note_num,
note.Elements()
.Where(h => h.Name.LocalName.ToLower() != "final")
.Select(h => HandleCreator.Create(h.Name.LocalName.ToLower(), h.GetAttribute(PresetReader.xtype), h.GetAttribute(PresetReader.xvalue))));
}
}
示例14: FromProjectDocument
public static IEnumerable<ItemGroupItem> FromProjectDocument(XDocument projectDocument)
{
return projectDocument
.Elements().Single(x => x.Name.LocalName == "Project")
.Elements().Where(x => x.Name.LocalName == "ItemGroup")
.SelectMany(x => x.Elements().Select(element => new ItemGroupItem(element)));
}
示例15: ParseXML
private void ParseXML(XDocument doc)
{
foreach (XElement block in doc.Elements("Service"))
{
foreach (XElement element in block.Elements("Service_Information").Elements())
{
ServiceInformation[element.Name.ToString()] = element.Value;
}
foreach (XElement element in block.Elements("Service_Config").Elements())
{
ServiceConfig[element.Name.ToString()] = element.Value;
}
foreach (XElement element in block.Elements("SIP_Headers").Elements())
{
SIPHeaders[element.Name.ToString()] = element.Value;
}
foreach (XElement element in block.Elements("SIP_Responses").Elements())
{
SIPResponses[element.Name.ToString()] = element.Value;
}
foreach (XElement element in block.Elements("Capabalities").Elements())
{
Capabilities[element.Name.ToString()] = element.Value;
}
foreach (XElement element in block.Elements("Metrics").Elements())
{
Metrics[element.Name.ToString()] = element.Value;
}
}
}