本文整理汇总了C#中System.Xml.Linq.XElement.XPathSelectElements方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.XPathSelectElements方法的具体用法?C# XElement.XPathSelectElements怎么用?C# XElement.XPathSelectElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.XPathSelectElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyDir
private static void ApplyDir(XElement dirElement, String path)
{
path = Path.Combine(path, dirElement.Attribute("name").Value);
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
foreach (var file in dirElement.XPathSelectElements("file"))
File.Create(Path.Combine(path, file.Attribute("name").Value)).Close();
foreach (var dir in dirElement.XPathSelectElements("directory"))
ApplyDir(dir, path);
}
示例2: LoadFromXml
public void LoadFromXml(XElement xml){
AddRules(ControllerRule.FromXml(xml .XPathSelectElements("on")));
xml.XPathSelectElements("map[@role]")
.Select(n => new{From = n.attr("role").ToUpper(), To = n.attr("as").ToUpper()})
.map(i => RoleMap.Add(i.From, i.To));
xml.XPathSelectElements("map[@user]")
.Select(n => new{From = n.attr("user").ToUpper(), To = n.attr("as").ToUpper()})
.map(i => UserMap.Add(i.From, i.To));
var def = xml.First("default");
if (def.yes()){
DefaultResult = def.Value;
}
}
示例3: AddToPackage
public void AddToPackage(string xPath, XElement document, string package, string formName)
{
var nodes = document.XPathSelectElements(xPath);
foreach (var node in nodes)
{
if (node.HasAttributes || node.Attribute("Name") == null ||node.Attribute("Name").Value != package)
{
continue;
}
foreach (var child in node.Elements())
{
if (child.Name != "OutputForms")
{
continue;
}
var newNode = new XElement("Form");
newNode.SetAttributeValue("Name", formName);
//node.Parent.AddAfterSelf(newNode);
child.Add(newNode);
}
}
}
示例4: Load
public virtual void Load(PengWorld world, XElement xWorld)
{
Contract.Requires(world != null);
Contract.Requires(xWorld != null);
foreach (XElement xObj in xWorld.XPathSelectElements(TA.XPathObjects))
{
List<ObjectArgumentInfo> args = new List<ObjectArgumentInfo>();
args.Add(new ObjectArgumentInfo(typeof(string), xObj.Attribute(TA.ObjectID).Value));
Type objectType;
if (xObj.Attribute(TA.ObjectType) != null)
{
objectType = Type.GetType(xObj.Attribute(TA.ObjectType).Value);
foreach (XElement xArg in xWorld.XPathSelectElements(TA.XPathObjectArgs))
{
if (xArg.Attribute(TA.ArgumentType) != null)
args.Add(GetObjectArgFromXml(xArg));
}
}
else
objectType = typeof(PengObject);
var ctor = objectType.GetConstructor(args.ConvertAll(x => x.Type).ToArray());
PengObject obj = (PengObject)ctor.Invoke(args.ConvertAll(x => x.Value).ToArray());
obj.LoadFromXml(xObj);
}
}
示例5: internalListAllUserRoleMaps
protected override IEnumerable<UserRoleMap> internalListAllUserRoleMaps(XElement lastx) {
var elements = lastx.XPathSelectElements("//map[@user and @as]");
foreach (var element in elements) {
var rm = new UserRoleMap {User = element.attr("user"), Role = element.attr("as")};
yield return rm;
}
}
示例6: Transform
public XElement Transform(XElement element)
{
// <p class="combat">
var combats = element.XPathSelectElements("p[@class='combat']").ToArray();
if (combats.Count() == 1)
{
var combat = combats.ElementAt(0);
// <button type="button" class="combat" onclick="Section.fight();">
combat.Name = "button";
combat.RemoveAttributes();
combat.Add(new XAttribute("type", "button"));
combat.Add(new XAttribute("class", "combat"));
combat.Add(new XAttribute("onclick", "Section.fight();"));
}
else
{
for (var index = 0; index < combats.Count(); index++)
{
var combat = combats.ElementAt(index);
// <button type="button" class="combat" onclick="Section.fight(X);">
combat.Name = "button";
combat.RemoveAttributes();
combat.Add(new XAttribute("type", "button"));
combat.Add(new XAttribute("class", "combat"));
combat.Add(new XAttribute("onclick", string.Format("Section.fight({0});", index)));
}
}
return element;
}
示例7: NavigationLinkBuilder
public NavigationLinkBuilder(string dimensionsPath)
{
dimensions = XElement.Load(dimensionsPath);
//Create context items for dimension name/value pairs
foreach(var node in dimensions.XPathSelectElements("//DIMENSION")) {
string name = node.Attribute("NAME").Value;
string id = node.Descendants("DIMENSION_ID").First().Attribute("ID").Value;
var item = new ContextItem() { Name = name, ID = id };
var count = 0;
foreach (var descendant in node.Descendants("DIMENSION_NODE"))
{
// Skip first
if (count != 0)
{
// get id
var a = descendant.Descendants("DVAL_ID").First().Attribute("ID").Value;
// get name from syn
var b = descendant.Descendants("SYN").First().Value;
item.Values.Add(b, new ContextItem() { Name = b, ID = a });
idToDimensions.Add(a, id);
}
count++;
}
contextItems.Add(name, item);
}
}
示例8: Parse
/// <summary>
/// Parse a XElement type parameter to a ComplexTypeElement instance.
/// </summary>
/// <param name="complexTypeElement">A ComplexType element.</param>
/// <returns>Returns a ComplexTypeElement instance.</returns>
public static ComplexTypeElement Parse(XElement complexTypeElement)
{
if (null == complexTypeElement)
{
return null;
}
string name = null != complexTypeElement.Attribute("Name") ? complexTypeElement.Attribute("Name").Value : null;
var props = new List<PropertyElement>();
string xPath = "./*[local-name()='Property']";
var propertyElements = complexTypeElement.XPathSelectElements(xPath, ODataNamespaceManager.Instance);
foreach (var propEle in propertyElements)
{
if (null != propEle.Attribute("Name") && null != propEle.Attribute("Type"))
{
AnnotationDVsManager accessor = AnnotationDVsManager.Instance();
string propertyName = string.Format("{0}_{1}", name, propEle.GetAttributeValue("Name"));
object defaultValue = accessor.GetDefaultValue(propertyName);
bool nullable = null != propEle.Attribute("Nullable") ? Convert.ToBoolean(propEle.Attribute("Nullable").Value) : true;
props.Add(new PropertyElement(propEle.Attribute("Name").Value.ToString(), propEle.Attribute("Type").Value.ToString(), defaultValue, nullable));
}
}
return new ComplexTypeElement(name, props);
}
示例9: ReplaceInForms
public void ReplaceInForms(string xPath, XElement document, Element previousParam, Element param)
{
var nodes = document.XPathSelectElements(xPath);
foreach (var node in nodes)
{
if (node.HasElements)
{
continue;
}
if (!node.HasAttributes || node.Attribute("Name").Value != previousParam.FormName || node.Attribute("Pdf").Value != previousParam.PdfName)
{
continue;
}
AttributeHelper.AttributeInNode("Name", previousParam.FormName, param.FormName, node);
AttributeHelper.AttributeInNode("Pdf", previousParam.PdfName, param.PdfName, node);
AttributeHelper.AttributeInNode("Doctype", previousParam.Doctype, param.Doctype, node);
AttributeHelper.AttributeInNode("DataNamePrefix", previousParam.DataNamePrefix, param.DataNamePrefix, node);
AttributeHelper.AttributeInNode("Docdesc", previousParam.Docdesc, param.Docdesc, node);
AttributeHelper.AttributeInNode("MergeID", previousParam.MergeId, param.MergeId, node);
AttributeHelper.AttributeInNode("Attachment", previousParam.Attachment, param.Attachment, node);
}
}
示例10: AddFrameXml
/// <summary>
/// Adds the frame XML.
/// </summary>
/// <param name="ui">The UI.</param>
public void AddFrameXml(XElement ui)
{
if (ui == null)
throw new ArgumentNullException("ui");
// Select all elements in the FrameXML that has a name
ui.XPathSelectElements("/descendant::*[@name]").ForEach(element => this.AddFrameXmlElement(element));
}
示例11: Parse
public static LinkedInLikesSummary Parse(XElement xLikes) {
return new LinkedInLikesSummary {
Total = xLikes.GetAttributeValueOrDefault<int>("total"),
Persons = (
from xPerson in xLikes.XPathSelectElements("like/person")
select LinkedInPersonSummary.Parse(xPerson)
).ToArray()
};
}
示例12: AddToForms
public void AddToForms(string xPath, XElement document, Element element)
{
var nodes = document.XPathSelectElements(xPath);
foreach (var node in nodes)
{
node.Add(AttributeHelper.AddNodeToForm(element));
}
}
示例13: RemoveFromPackages
public void RemoveFromPackages(string xPath, XElement document, Element param)
{
var nodes = document.XPathSelectElements(xPath);
foreach (var node in nodes.Where(node => node.Name == "Form" && node.Attribute("Name") != null && node.Attribute("Name").Value == param.FormName))
{
node.Remove();
}
}
示例14: RemoveFromPackage
public void RemoveFromPackage(string xPath, XElement document, string package, string formName)
{
var nodes = document.XPathSelectElements(xPath);
foreach (var node in nodes.Where(node => node.HasAttributes && node.Attribute("Name") != null && node.Attribute("Name").Value == formName &&
node.Parent.Parent.Attribute("Name").Value == package))
{
node.Remove();
}
}
示例15: ReplaceInPdfs
public void ReplaceInPdfs(string xPath, XElement document, Element previousParam, Element param)
{
var nodes = document.XPathSelectElements(xPath);
foreach (var node in nodes.Where(node => node.HasAttributes && node.Attribute("Name").Value == previousParam.PdfName && node.Attribute("File").Value == previousParam.PdfFilePath))
{
node.Attribute("Name").Value = param.PdfName;
node.Attribute("File").Value = param.PdfFilePath;
}
}