本文整理汇总了C#中System.Xml.Linq.XDocument.XPathSelectElements方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.XPathSelectElements方法的具体用法?C# XDocument.XPathSelectElements怎么用?C# XDocument.XPathSelectElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.XPathSelectElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransformOutput
public XDocument TransformOutput(XDocument output)
{
var elements = output.XPathSelectElements("//jetbrains.buildServer.messages.BuildMessage1"
+ "[./myTypeId[text()='BlockStart'] and "
+ ".//blockType[text() ='$TEST_BLOCK$']]");
var tests = elements.Select(x => new TestResult
{
FullName = x.XPathSelectElement(".//blockName").Value,
RunTime = long.Parse(x.XPathSelectElement(".//myTimestamp").Value),
Succeeded = x.NextNode.XPathSelectElement(".//myTypeId").Value != "TestFailure"
})
.OrderBy(x => x.RunTime);
var testsToRemove = from testResult in tests.GroupBy(x => x.FullName)
where testResult.Any(x => x.Succeeded)
select testResult.Key;
foreach (var testToRemove in testsToRemove)
{
output.XPathSelectElements(
"//jetbrains.buildServer.messages.BuildMessage1[./myTypeId[text()='TestFailure'] and .//testName[text()='"
+ testToRemove + "']]").Remove();
}
return output;
}
示例2: CreateDynamicContent
// Creates the dynamic content from the twitter results
RootElement CreateDynamicContent (XDocument doc)
{
var users = doc.XPathSelectElements ("./statuses/status/user").ToArray ();
var texts = doc.XPathSelectElements ("./statuses/status/text").Select (x=>x.Value).ToArray ();
var people = doc.XPathSelectElements ("./statuses/status/user/name").Select (x=>x.Value).ToArray ();
var section = new Section ();
var root = new RootElement ("Tweets") { section };
for (int i = 0; i < people.Length; i++){
var line = new RootElement (people [i]) {
new Section ("Profile"){
new StringElement ("Screen name", users [i].XPathSelectElement ("./screen_name").Value),
new StringElement ("Name", people [i]),
new StringElement ("oFllowers:", users [i].XPathSelectElement ("./followers_count").Value)
},
new Section ("Tweet"){
new StringElement (texts [i])
}
};
section.Add (line);
}
return root;
}
示例3: GetContentByXPath
private XDocument GetContentByXPath(string xpath, XDocument content)
{
var xdoc = XDocument.Parse("<content></content>");
xdoc.Root.Add(content.XPathSelectElements(xpath));
return xdoc;
}
示例4: Parse
public static IBArchive Parse(XDocument xDoc)
{
IBArchive ibArchive = new IBArchive();
foreach (XAttribute attr in xDoc.Root.Attributes())
{
if (attr.Name == "type")
ibArchive.Type = attr.Value;
if (attr.Name == "version")
ibArchive.Version = attr.Value;
}
var elements = xDoc.XPathSelectElements(@"/archive/data/*");
foreach (var element in elements)
{
var key = element.Attributes().Where(attr => attr.Name == "key").FirstOrDefault();
if (key != null && element.Attribute("key").Value.StartsWith("IBDocument."))
{
//IBDocument.Parse(ibArchive.Data, element);
}
}
//if (xmlReader.Name == "archive")
//{
// while (xmlReader.MoveToNextAttribute())
// {
// if (xmlReader.Name == "type")
// ibArchive.Type = xmlReader.Value;
// else if (xmlReader.Name == "version")
// ibArchive.Version = xmlReader.Value;
// }
//}
return ibArchive;
}
示例5: TraverseXmlDocument
private static void TraverseXmlDocument(XDocument doc)
{
foreach (var leagueElement in doc.XPathSelectElements("leagues-and-teams/league"))
{
AddLeague(leagueElement);
}
}
示例6: Main
static void Main()
{
string documentPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\expenses.xml";
var xmlDocument = new XDocument();
try
{
xmlDocument = XDocument.Load(documentPath);
Console.WriteLine("XML file has been found!");
}
catch (FileNotFoundException)
{
Console.WriteLine("File not found!");
}
var nodes = xmlDocument.XPathSelectElements("//expenses-by-month/vendor");
foreach (var vendor in nodes)
{
string vendorName = vendor.Attribute("name").Value;
var expenses = vendor.Elements("expenses");
foreach (var expense in expenses)
{
DateTime month = DateTime.Parse(expense.Attribute("month").Value);
decimal amount = decimal.Parse(expense.Value);
AddVendorExpense(vendorName, month, amount);
}
}
}
示例7: Transform
public virtual bool Transform(XDocument document)
{
if (document == null) { return false; }
var elementArray = document.XPathSelectElements(this.Xpath).ToArray<XElement>();
if (elementArray.Length == 0) { return false; }
var changeMade = false;
foreach (var element in elementArray)
{
var attribute = element.Attribute(this.AttributeName);
if (attribute == null) { continue; }
string newValue = null;
if (this.ChangeType == AttributeValueChangeType.Replace)
{
newValue = this.NewValue;
}
else if (this.ChangeType == AttributeValueChangeType.Prepend)
{
newValue = this.NewValue + attribute.Value;
}
else if (this.ChangeType == AttributeValueChangeType.Append)
{
newValue = attribute.Value + this.NewValue;
}
if (!string.IsNullOrEmpty(newValue) && ! newValue.Equals(attribute.Value))
{
attribute.Value = newValue;
changeMade = true;
}
}
return changeMade;
}
示例8: ReportItems
private static string ReportItems(XDocument xdoc, string path)
{
var sb = new StringBuilder();
foreach (var e in xdoc.XPathSelectElements(path).Elements())
{
var roles = ((string)e.Attribute("roles"))?.Split(',');
if (roles != null)
if (!roles.Any(rr => DbUtil.Db.CurrentUser.Roles.Contains(rr)))
continue;
var tb = new TagBuilder("li");
switch (e.Name.LocalName)
{
case "Report":
var a = new TagBuilder("a");
a.MergeAttribute("href", e.Attribute("link").Value);
var t = e.Attribute("target");
if (t != null)
a.MergeAttribute("target", t.Value);
a.SetInnerText(e.Value);
tb.InnerHtml = a.ToString();
break;
case "Header":
tb.AddCssClass("dropdown-header");
tb.SetInnerText(e.Value);
break;
case "Space":
tb.AddCssClass("divider");
break;
}
sb.AppendLine(tb.ToString());
}
return sb.ToString();
}
示例9: ExtractUriFromLink
public static string ExtractUriFromLink(string relEndsWith, XDocument xml, XmlNamespaceManager namespaceManager)
{
return xml
.XPathSelectElements("//dp:link/dp:rel", namespaceManager)
.Where(element => element.Value.EndsWith(relEndsWith))
.First()
.XPathSelectElement("../dp:uri", namespaceManager)
.Value;
}
示例10: AddReferencesFromProject
private static void AddReferencesFromProject(DependencyGraphBuilder builder, object proj, XDocument xproject, string projectFile,
HashSet<string> referencedProjects)
{
foreach (var xtarget in xproject.XPathSelectElements("/projectDescription/projects/project"))
{
var targetProjectName = xtarget.Value;
if (!referencedProjects.Contains(targetProjectName))
builder.AddProjectReference(proj, targetProjectName, null, null, null, ToLocation(projectFile, xtarget), null);
}
}
示例11: Execute
public NBi.Core.ResultSet.ResultSet Execute(XDocument items)
{
var result = from item in items.XPathSelectElements(@from)
select GetObj(item);
var builder = new ResultSetBuilder();
var rows = result.ToArray();
var resultSet = builder.Build(rows);
return resultSet;
}
示例12: ProcessXML
public int ProcessXML(XDocument file,string userid)
{
string level;
SqlCommand sqlCmd1;
SqlDataReader read1;
SqlConnection sqlCon = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
sqlCon.Open();
if (userid == null)
userid = "PatientFolder";
string FolderPath = @"D:\C sharp code\LongTermCare(Xml)\Search\Query_Xml\" + userid;
DirectoryInfo DIFO = new DirectoryInfo(FolderPath);//判斷資料夾存在否
if (!DIFO.Exists)
{
DIFO.Create();
}
level = file.Root.Name.ToString();
IEnumerable<XElement> list1 = file.XPathSelectElements(level);//root node
int Querycount = 0;
foreach (XElement item in list1.Elements())
{//get fieldname and value
if (item.Value.ToString() != "")
{
QFieldName[Querycount] = item.Attribute("FieldName").Value.ToString().Replace(" ", "");
QVR[Querycount] = item.Attribute("VR").Value.ToString();
Qvalue[Querycount++] = item.Value.ToString();
}
}
int checkwhere = 0;
for (int i = 0; i < Querycount; i++)//saerch tablename then combine SQL
{
sqlCmd1 = new SqlCommand("select DISTINCT TableName from TableFields where FieldName='" + QFieldName[i] + "'", sqlCon);
read1 = sqlCmd1.ExecuteReader();
read1.Read();
if (Qvalue[i] != "*")
{
if (++checkwhere == 1)
Terms = "where" + ' ' + Terms;
Terms += read1["TableName"].ToString() + "." + QFieldName[i];
if ((QVR[i] == "DA" || QVR[i] == "TM") && Qvalue[i].Length == 9)
Terms += Qvalue[i];
else if ((QVR[i] == "DA" || QVR[i] == "TM") && Qvalue[i].Length > 9)
{
string[] strs = Qvalue[i].Split('-');
Terms += ">" + strs[0] + " and " + read1["TableName"].ToString() + "." + QFieldName[i] + "<" + strs[1];
}
else
Terms += "=" + "'" + Qvalue[i] + "'";
if (i < Querycount - 1)
Terms += ' ' + "and ";
}
}
return Query(level, userid);
}
示例13: ResolveAbstractPatterns
/// <summary>
/// Resolves all abstract patterns in the schema by replacing
/// parameter references by actual parameter values in all enclosed
/// attributes that contain queries.
/// </summary>
/// <param name="xSchema">Validation schema</param>
/// <param name="nsManager">Namespace manager</param>
/// <exception cref="ArgumentNullException" />
public static void ResolveAbstractPatterns(XDocument xSchema, XmlNamespaceManager nsManager)
{
if (xSchema == null)
{
throw new ArgumentNullException("xSchema");
}
if (nsManager == null)
{
throw new ArgumentNullException("nsManager");
}
// select abstract patterns
Dictionary<string, XElement> dicAPs = new Dictionary<string, XElement>();
foreach (XElement xAbstractPattern in xSchema.XPathSelectElements("//sch:pattern[@abstract='true']", nsManager))
{
string id = xAbstractPattern.Attribute(XName.Get("id")).Value;
dicAPs.Add(id, xAbstractPattern);
}
if (dicAPs.Count > 0)
{
// select instances
List<XElement> listInstances = new List<XElement>();
foreach (XElement xInstance in xSchema.XPathSelectElements("//sch:pattern[@is-a]", nsManager))
{
listInstances.Add(xInstance);
}
// replace instances
foreach (XElement xInstance in listInstances)
{
ReplaceAbstractPatternInstance(dicAPs, xInstance, nsManager);
}
// remove abstract patterns
foreach (KeyValuePair<string, XElement> item in dicAPs)
{
item.Value.Remove();
}
}
}
示例14: MainWindow
public MainWindow()
{
InitializeComponent();
try
{
// app.configista löytyvä viinit1.xml
string wines = ConfigurationManager.AppSettings.Get("XMLFile");
//ladataan xml-tiedosto
doc = XDocument.Load(wines);
//säätöä
/**var query = from w in doc.Descendants("wine")
select new {
//nimi = w.Element("nimi").Value,
maa = w.Element("maa").Value,
//arvio = w.Element("arvio").Value
}; **/
// maat comboboxiin
foreach (var elem in doc.XPathSelectElements("//maa"))
{
if (!cmbValinta.Items.Contains(elem.Value))
{
cmbValinta.Items.Add(elem.Value);
}
}
// kaikki vinetot datagridiin
foreach (var elem in doc.XPathSelectElements("//wine"))
{
dgViinit.Items.Add(elem).ToString();
}
cmbValinta.Items.Add("Kaikki vinetot");
}
catch (Exception ex)
{
MessageBox.Show("Erroria: " + ex.Message);
}
}
示例15: GetLinks
private static IEnumerable<Link> GetLinks(XDocument doc, Func<string, Link> factory)
{
var links = new List<Link>();
var reader = doc.CreateReader();
var xmlNameTable = reader.NameTable;
_NamespaceManager = new XmlNamespaceManager(xmlNameTable);
_NamespaceManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml");
var elements = doc.XPathSelectElements("//xhtml:link[@href]|//xhtml:a[@href]",_NamespaceManager);
foreach(var linkElement in elements) {
links.AddRange(CreateLinks(linkElement, factory));
}
var formElements = doc.XPathSelectElements("//xhtml:form[@action]", _NamespaceManager);
foreach (var linkElement in formElements) {
links.AddRange(CreateFormLinks(linkElement, factory));
}
return links;
}