本文整理汇总了C#中System.Xml.XmlNode.SelectSingleElement方法的典型用法代码示例。如果您正苦于以下问题:C# XmlNode.SelectSingleElement方法的具体用法?C# XmlNode.SelectSingleElement怎么用?C# XmlNode.SelectSingleElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlNode
的用法示例。
在下文中一共展示了XmlNode.SelectSingleElement方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessSageLinkElement
internal static XmlNode ProcessSageLinkElement(SageContext context, XmlNode node)
{
Contract.Requires<ArgumentNullException>(node != null);
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
XmlElement linkElem = (XmlElement) node;
string linkName = context.ProcessText(linkElem.GetAttribute("ref"));
bool rawString = linkElem.GetAttribute("raw").EqualsAnyOf("1", "yes", "true");
if (!string.IsNullOrEmpty(linkName) && rawString)
{
if (context.Url.Links.ContainsKey(linkName))
{
linkElem.InnerText = context.Url.Links[linkName].Value;
}
return linkElem;
}
string linkHref = context.Url.GetUrl(linkElem);
if (!string.IsNullOrEmpty(linkHref))
{
linkElem.SetAttribute("href", linkHref);
}
foreach (XmlNode child in node.ChildNodes)
{
XmlNode processed = NodeEvaluator.GetNodeHandler(child)(context, child);
if (processed != null)
node.ReplaceChild(processed, child);
else
node.RemoveChild(child);
}
return linkElem;
}
示例2: ProcessSageUrlElement
internal static XmlNode ProcessSageUrlElement(SageContext context, XmlNode node)
{
Contract.Requires<ArgumentNullException>(node != null);
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
string linkHref = context.Url.GetUrl((XmlElement) node);
if (!string.IsNullOrEmpty(linkHref))
{
if (node.NodeType == XmlNodeType.Element)
return node.OwnerDocument.CreateTextNode(linkHref);
}
return node;
}
示例3: ProcessHrefAttribute
internal static XmlNode ProcessHrefAttribute(SageContext context, XmlNode node)
{
Contract.Requires<ArgumentNullException>(node != null);
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
node.InnerText = context.ProcessText(node.InnerText);
return node;
}
示例4: ProcessSageBaseHrefElement
internal static XmlNode ProcessSageBaseHrefElement(SageContext context, XmlNode node)
{
Contract.Requires<ArgumentNullException>(node != null);
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
XmlElement result = node.OwnerDocument.CreateElement("base", XmlNamespaces.XHtmlNamespace);
result.SetAttribute("href", context.BaseHref);
return result;
}
示例5: ProcessContextSwitchNode
internal static XmlNode ProcessContextSwitchNode(SageContext context, XmlNode switchNode)
{
if (switchNode.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return switchNode;
XmlElement switchElem = (XmlElement) switchNode;
string propName = switchElem.GetAttribute("property");
string key = switchElem.GetAttribute("key");
if (string.IsNullOrEmpty(propName))
{
log.ErrorFormat("The switch node in document '{0}' is missing the required property attribute",
switchNode.OwnerDocument.BaseURI);
return switchNode;
}
string propValue = SageContext.GetContextProperty(context, propName, key);
int caseNum = 0;
bool caseFound = false;
XmlDocumentFragment result = switchNode.OwnerDocument.CreateDocumentFragment();
foreach (XmlElement caseNode in switchNode.SelectNodes("context:case", XmlNamespaces.Manager))
{
string testValue = caseNode.GetAttribute("test");
if (string.IsNullOrEmpty(testValue))
{
log.WarnFormat(
"The case node with index {0} of switch node '{1}' in document '{2}' didn't specify a test condition.",
caseNum, propName, switchNode.OwnerDocument.BaseURI);
continue;
}
if (testValue.Equals(propValue, StringComparison.InvariantCultureIgnoreCase))
{
foreach (XmlNode node in caseNode.SelectNodes("node()"))
result.AppendChild(context.ProcessNode(node));
caseFound = true;
break;
}
caseNum += 1;
}
if (!caseFound)
{
XmlNode defaultNode = switchNode.SelectSingleNode("context:default", XmlNamespaces.Manager);
if (defaultNode != null)
{
foreach (XmlNode node in defaultNode.SelectNodes("node()"))
result.AppendChild(context.ProcessNode(node));
}
}
return result;
}
示例6: ProcessContextIfNode
internal static XmlNode ProcessContextIfNode(SageContext context, XmlNode node)
{
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
XmlElement element = (XmlElement) node;
XmlDocumentFragment result = node.OwnerDocument.CreateDocumentFragment();
string expression = element.GetAttribute("expression");
string propName = element.GetAttribute("property");
string key = element.GetAttribute("key");
string equals = element.GetAttribute("equals");
string notEquals = element.GetAttribute("not-equals");
bool nodeValid = false;
if (!string.IsNullOrWhiteSpace(expression))
{
var text = context.textEvaluator.Process(expression);
nodeValid = !string.IsNullOrWhiteSpace(text);
}
else
{
string propValue = SageContext.GetContextProperty(context, propName, key);
if (notEquals != string.Empty)
nodeValid = !propValue.Equals(notEquals, StringComparison.InvariantCultureIgnoreCase);
else if (equals != string.Empty)
nodeValid = propValue.Equals(equals, StringComparison.InvariantCultureIgnoreCase);
}
if (!nodeValid)
return null;
foreach (XmlNode child in node.SelectNodes("node()"))
result.AppendChild(context.ProcessNode(child));
return result;
}
示例7: ProcessBaseHrefNode
internal static XmlNode ProcessBaseHrefNode(SageContext context, XmlNode node)
{
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
XmlElement result = node.OwnerDocument.CreateElement("base", XmlNamespaces.XHtmlNamespace);
result.SetAttribute("href", context.BaseHref);
return result;
}
示例8: ProcessSageVersionNode
internal static XmlNode ProcessSageVersionNode(SageContext context, XmlNode node)
{
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
return node.OwnerDocument.CreateTextNode(version);
}
示例9: ProcessContextValueNode
internal static XmlNode ProcessContextValueNode(SageContext context, XmlNode node)
{
if (node.SelectSingleElement("ancestor::sage:literal", XmlNamespaces.Manager) != null)
return node;
XmlElement valueElem = (XmlElement) node;
string xpath = valueElem.GetAttribute("xpath");
if (!string.IsNullOrWhiteSpace(xpath))
{
XmlNode value = node.SelectSingleNode(xpath, XmlNamespaces.Manager);
node.OwnerDocument.CreateTextNode(value.InnerText);
}
string propName = valueElem.GetAttribute("property");
if (string.IsNullOrWhiteSpace(propName))
return node.OwnerDocument.CreateTextNode(context.textEvaluator.Process(valueElem.InnerText));
string propKey = valueElem.GetAttribute("key");
string propValue = SageContext.GetContextProperty(context, propName, propKey);
if (propValue != null)
return node.OwnerDocument.CreateTextNode(propValue);
// default: return node as is
return node;
}