本文整理汇总了C#中System.Xml.Linq.XDocument.XPathSelectElement方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.XPathSelectElement方法的具体用法?C# XDocument.XPathSelectElement怎么用?C# XDocument.XPathSelectElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.XPathSelectElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModifyConfig
public override void ModifyConfig(XDocument doc)
{
const string Instructions = @"<MessageForwardingInCaseOfFaultConfig
ErrorQueue=""The queue to which errors will be forwarded."" />";
var sectionElement = doc.XPathSelectElement("/configuration/configSections/section[@name='MessageForwardingInCaseOfFaultConfig' and @type='NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core']");
if (sectionElement == null)
{
doc.XPathSelectElement("/configuration/configSections").Add(new XElement("section",
new XAttribute("name",
"MessageForwardingInCaseOfFaultConfig"),
new XAttribute("type",
"NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core")));
}
var forwardingElement = doc.XPathSelectElement("/configuration/MessageForwardingInCaseOfFaultConfig");
if (forwardingElement == null)
{
doc.Root.LastNode.AddAfterSelf(new XComment(Instructions),
new XElement("MessageForwardingInCaseOfFaultConfig",
new XAttribute("ErrorQueue", "error")));
}
}
示例2: addElements
private void addElements (XDocument manifest, params string[] elements) {
foreach (var element in elements) {
if (null == manifest.XPathSelectElement(element, this)) {
manifest.XPathSelectElement(getParentElement(element), this).Add(getElement(element));
}
}
}
示例3: DrawRegistryDocument
public string DrawRegistryDocument(XDocument xd)
{
string sHTML = "";
if (xd.XPathSelectElement("registry") != null)
{
sHTML += "<div class=\"ui-widget-content ui-corner-bottom registry\">";
sHTML += " <div class=\"ui-state-default registry_section_header\" xpath=\"registry\">"; //header
sHTML += " <div class=\"registry_section_header_title\">Registry</div>";
sHTML += "<div class=\"registry_section_header_icons\">"; //step header icons
sHTML += "<span id=\"registry_refresh_btn\" class=\"pointer\">" +
"<img style=\"width:10px; height:10px;\" src=\"../images/icons/reload_16.png\"" +
" alt=\"\" title=\"Refresh\" /></span>";
sHTML += "<span class=\"registry_node_add_btn pointer\"" +
" xpath=\"registry\">" +
"<img style=\"width:10px; height:10px;\" src=\"../images/icons/edit_add.png\"" +
" alt=\"\" title=\"Add another...\" /></span>";
sHTML += "</div>"; //end step header icons
sHTML += " </div>"; //end header
foreach (XElement xe in xd.XPathSelectElement("registry").Nodes())
{
sHTML += DrawRegistryNode(xe, "registry/" + xe.Name.ToString());
}
sHTML += "</div>";
}
if (sHTML.Length == 0)
sHTML = "Registry is empty.";
return sHTML;
}
示例4: ModifyConfig
public override void ModifyConfig(XDocument doc)
{
// Add the new audit config section, if the ForwardReceivedMessagesTo attribute has not been set in the UnicastBusConfig.
var frmAttributeEnumerator = (IEnumerable)doc.XPathEvaluate("/configuration/UnicastBusConfig/@ForwardReceivedMessagesTo");
var isForwardReceivedMessagesAttributeDefined = frmAttributeEnumerator.Cast<XAttribute>().Any();
// Then add the audit config
var sectionElement =
doc.XPathSelectElement(
"/configuration/configSections/section[@name='AuditConfig' and @type='NServiceBus.Config.AuditConfig, NServiceBus.Core']");
if (sectionElement == null)
{
if (isForwardReceivedMessagesAttributeDefined)
doc.XPathSelectElement("/configuration/configSections").Add(new XComment(exampleAuditConfigSection));
else
doc.XPathSelectElement("/configuration/configSections").Add(new XElement("section",
new XAttribute("name",
"AuditConfig"),
new XAttribute("type",
"NServiceBus.Config.AuditConfig, NServiceBus.Core")));
}
var forwardingElement = doc.XPathSelectElement("/configuration/AuditConfig");
if (forwardingElement == null)
{
doc.Root.LastNode.AddAfterSelf(new XComment(Instructions),
isForwardReceivedMessagesAttributeDefined ? (object) new XComment(@"Since we detected that you already have forwarding setup we haven't enabled the audit feature.
Please remove the ForwardReceivedMessagesTo attribute from the UnicastBusConfig and uncomment the AuditConfig section.
<AuditConfig QueueName=""audit"" />") : new XElement("AuditConfig", new XAttribute("QueueName", "audit")));
}
}
示例5: Save
public static void Save(BlogPost post, string file) {
post.LastModified = DateTime.UtcNow;
XDocument doc = new XDocument(
new XElement("post",
new XElement("title", post.Title),
new XElement("slug", post.Slug),
new XElement("author", post.Author),
new XElement("pubDate", post.PubDate.ToString("yyyy-MM-dd HH:mm:ss")),
new XElement("lastModified", post.LastModified.ToString("yyyy-MM-dd HH:mm:ss")),
new XElement("content", post.Content),
new XElement("ispublished", post.IsPublished),
new XElement("categories", string.Empty),
new XElement("comments", string.Empty)
));
XElement categories = doc.XPathSelectElement("post/categories");
foreach (string category in post.Categories) {
categories.Add(new XElement("category", category));
}
XElement comments = doc.XPathSelectElement("post/comments");
doc.Save(file);
}
示例6: InsertJob
public static void InsertJob(XDocument jobXml)
{
string username = jobXml.XPathSelectElement("data/username").Value;
Console.WriteLine("Username: {0}", username);
Console.WriteLine("Job type: {0}", jobXml.XPathSelectElement("data/").Value);
}
示例7: GetProjectOutputMode
public OutputPathMode GetProjectOutputMode(XDocument document)
{
var platformSpecificOutputFolderElement = document.XPathSelectElement("/Project/Properties/PlatformSpecificOutputFolder");
var projectSpecificOutputFolderElement = document.XPathSelectElement("/Project/Properties/ProjectSpecificOutputFolder");
var platformSpecificOutputFolder = true;
var projectSpecificOutputFolder = false;
if (platformSpecificOutputFolderElement != null)
{
platformSpecificOutputFolder = platformSpecificOutputFolderElement.Value.ToLowerInvariant() != "false";
}
if (projectSpecificOutputFolderElement != null)
{
projectSpecificOutputFolder = projectSpecificOutputFolderElement.Value.ToLowerInvariant() == "true";
}
var outputMode = OutputPathMode.BinConfiguration;
if (projectSpecificOutputFolder)
{
outputMode = OutputPathMode.BinProjectPlatformArchConfiguration;
}
if (platformSpecificOutputFolder)
{
outputMode = OutputPathMode.BinPlatformArchConfiguration;
}
return outputMode;
}
示例8: Save
// Can this be done async?
public static void Save(Post post)
{
string file = Path.Combine(_folder, post.ID + ".xml");
post.LastModified = DateTime.UtcNow;
XDocument doc = new XDocument(
new XElement("post",
new XElement("title", post.Title),
new XElement("slug", post.Slug),
new XElement("author", post.Author),
new XElement("pubDate", post.PubDate.ToString("yyyy-MM-dd HH:mm:ss")),
new XElement("lastModified", post.LastModified.ToString("yyyy-MM-dd HH:mm:ss")),
new XElement("excerpt", post.Excerpt),
new XElement("content", post.Content),
new XElement("ispublished", post.IsPublished),
new XElement("categories", string.Empty),
new XElement("comments", string.Empty)
));
XElement categories = doc.XPathSelectElement("post/categories");
foreach (string category in post.Categories)
{
categories.Add(new XElement("category", category));
}
XElement comments = doc.XPathSelectElement("post/comments");
foreach (Comment comment in post.Comments)
{
comments.Add(
new XElement("comment",
new XElement("author", comment.Author),
new XElement("email", comment.Email),
new XElement("website", comment.Website),
new XElement("ip", comment.Ip),
new XElement("userAgent", comment.UserAgent),
new XElement("date", comment.PubDate.ToString("yyyy-MM-dd HH:m:ss")),
new XElement("content", comment.Content),
new XAttribute("isAdmin", comment.IsAdmin),
new XAttribute("isApproved", comment.IsApproved),
new XAttribute("id", comment.ID)
));
}
if (!File.Exists(file)) // New post
{
var posts = GetAllPosts();
posts.Insert(0, post);
posts.Sort((p1, p2) => p2.PubDate.CompareTo(p1.PubDate));
HttpRuntime.Cache.Insert("posts", posts);
}
else
{
Blog.ClearStartPageCache();
}
doc.Save(file);
}
示例9: SimpleWriting
private void SimpleWriting()
{
XDocument xd;
XElement root;
XElement child;
xd =
new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Employee Records"),
new XElement("Employees"));
root = xd.XPathSelectElement("//Employees");
child = new XElement("Employee",
new XElement("id", 1),
new XElement("FirstName", "Bruce"),
new XElement("LastName", "Jones"));
root.Add(child);
xd.Save(AppConfig.XmlFile);
txtResult.Text = xd.ToString();
}
示例10: Transform
public virtual bool Transform(XDocument document)
{
if (document == null) { return false; }
var element = document.XPathSelectElement(this.Xpath);
if (element == null)
{
return false;
}
var attribute = element.Attribute(this.AttributeName);
if (attribute == null)
{
return false;
}
var path = Path.Combine(this.FilePath, attribute.Value);
if (!File.Exists(path))
{
throw new Exception(string.Format("Cannot find {0}", path));
}
var root = XDocument.Load(path).Root;
if (!element.ToString().Equals(root.ToString()))
{
element.ReplaceWith(root);
return true;
}
return false;
}
示例11: DesktopServiceConfiguration
protected DesktopServiceConfiguration(string path, bool useRemoteConfig)
{
filePath = path;
configDoc = XDocument.Load(path);
XElement configXml = configDoc.XPathSelectElement("//selfServiceDesktops");
if (configXml == null) {
throw new ArgumentException("No <selfServiceDesktops/> configuration element found in : " + path);
}
config = Deserialize(configXml);
if (useRemoteConfig && (config.RemoteConfig != null)) {
try {
configXml = GetXml(new Uri(config.RemoteConfig));
string remoteConfig = config.RemoteConfig;
config = Deserialize(configXml);
// If the remote config does not have an agent URI, infer it from the remote Url in the local config
if (config.AgentUri == null) {
config.SetAgentUriFrom(remoteConfig);
}
} catch (Exception e) {
throw new ConfigurationErrorsException("Unable to load configuration from remote server", e);
}
}
ValidateConfiguration();
}
示例12: Main
static void Main(string[] args)
{
var path = @"d:\1";
var document = new XDocument(
new XDeclaration("1.0", "UTF-8", null),
new XElement("root-dir",
new XAttribute("path", path)));
var files = Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories);
foreach (var file in files)
{
var fileDirectories = file.Replace(path, "")
.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
var len = fileDirectories.Length;
var root = document.Element("root-dir");
XElement dir = root;
for (int i = 0; i < len - 1; i++)
{
dir = document.XPathSelectElement(String.Format("//dir[@name = '{0}']", fileDirectories[i]));
if (dir == null)
{
if (i < 1)
{
dir = root;
}
else
{
dir = document.XPathSelectElement(String.Format("//dir[@name = '{0}']", fileDirectories[i - 1]));
}
var newDir = new XElement("dir",
new XAttribute("name", fileDirectories[i]));
dir.Add(newDir);
dir = newDir;
}
}
dir.Add(new XElement("file",
new XAttribute("name", fileDirectories[len - 1])));
}
Console.WriteLine(document.Declaration);
Console.WriteLine(document);
}
示例13: removeElements
private void removeElements (XDocument manifest, params string[] elements) {
foreach (var element in elements) {
var e = manifest.XPathSelectElement(element, this);
if (null != e) {
e.Remove();
}
}
}
示例14: Parse
/// <summary>
/// Parses the results of a Core Status command.
/// </summary>
/// <param name="xml">The XML Document to parse.</param>
/// <returns></returns>
public List<CoreResult> Parse(XDocument xml) {
var statusNode = xml.XPathSelectElement("response/lst[@name='status']");
if (statusNode == null || !statusNode.HasElements)
return new List<CoreResult>();
var results = statusNode.Elements().Select(ParseCore).ToList();
return results;
}
示例15: GetElementsToKeep
private IList<XElement> GetElementsToKeep(XDocument copyDocument, string xpath)
{
var elementsToKeep = new List<XElement>();
var element = copyDocument.XPathSelectElement(xpath, new SimpleXmlNamespaceResolver(copyDocument));
elementsToKeep.AddRange(element.AncestorsAndSelf());
elementsToKeep.AddRange(element.Descendants());
return elementsToKeep;
}