本文整理汇总了C#中XNode类的典型用法代码示例。如果您正苦于以下问题:C# XNode类的具体用法?C# XNode怎么用?C# XNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XNode类属于命名空间,在下文中一共展示了XNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: XPathValues
//public static IEnumerable<string> XPathValues(XElement xe, string xpath)
public static IEnumerable<string> XPathValues(XNode node, string xpath)
{
if (node == null)
return new string[0];
return XPathResultGetValues(node.XPathEvaluate(xpath));
}
开发者ID:labeuze,项目名称:source,代码行数:8,代码来源:Xml.cs
示例2: WriteElement
private void WriteElement(XNode node, XmlWriter writer)
{
writer.WriteStartElement(node.Name);
foreach (var attr in node.Attributes)
{
if (attr.Match == MatchType.Change || attr.Match == MatchType.NoMatch)
writer.WriteAttributeString(attr.Name, attr.XmlNode.Value);
}
foreach (var text in node.Texts)
{
if (text.Match == MatchType.Change || text.Match == MatchType.NoMatch)
writer.WriteValue(text.XmlNode.Value);
}
foreach (var element in node.Elements)
{
if (element.Match == MatchType.Change)
WriteElement(element, writer);
if (element.Match == MatchType.NoMatch)
writer.WriteRaw(element.XmlNode.OuterXml);
}
writer.WriteEndElement();
}
开发者ID:clone278,项目名称:FatAntelope,代码行数:27,代码来源:DebugDiffWriter.cs
示例3: ReplaceAppSettingOrConnectionString
static IEnumerable<string> ReplaceAppSettingOrConnectionString(XNode document, string xpath, string keyAttributeName, string keyAttributeValue, string valueAttributeName, VariableDictionary variables)
{
var changes = new List<string>();
var settings = (
from element in document.XPathSelectElements(xpath)
let keyAttribute = element.Attribute(keyAttributeName)
where keyAttribute != null
where string.Equals(keyAttribute.Value, keyAttributeValue, StringComparison.InvariantCultureIgnoreCase)
select element).ToList();
if (settings.Count == 0)
return changes;
var value = variables.Get(keyAttributeValue) ?? string.Empty;
foreach (var setting in settings)
{
changes.Add(string.Format("Setting '{0}' = '{1}'", keyAttributeValue, value));
var valueAttribute = setting.Attribute(valueAttributeName);
if (valueAttribute == null)
{
setting.Add(new XAttribute(valueAttributeName, value));
}
else
{
valueAttribute.SetValue(value);
}
}
return changes;
}
开发者ID:merbla,项目名称:Calamari,代码行数:32,代码来源:ConfigurationVariablesReplacer.cs
示例4: SelectWithRootNamespace
static IEnumerable<XElement> SelectWithRootNamespace(XNode container, string namespaceName, IEnumerable<Traversal> traversals)
{
var nav = container.CreateNavigator();
var xPath = traversals.ToXPath("x");
var manager = new XmlNamespaceManager(nav.NameTable);
manager.AddNamespace("x", namespaceName);
return container.XPathSelectElements(xPath, manager);
}
开发者ID:joshski,项目名称:neffigy,代码行数:8,代码来源:XContainerExtensions.cs
示例5: LoadModules
private void LoadModules(XNode configRoot)
{
var elements = configRoot.XPathSelectElements("modules/module");
_moduleInstancesInstances = new List<ModuleInstance>(elements.Count());
elements.ForEachItem(m =>
{
var type = m.Attribute("Type").Value;
var active = m.Attribute("Active")?.Value.ToBoolean() ?? true;
_moduleInstancesInstances.Add(new ModuleInstance(type, active));
});
}
开发者ID:saturn72,项目名称:Saturn72.Core,代码行数:11,代码来源:XmlConfigManager.cs
示例6: Merge
public XElement Merge(XElement masterElement, XNode sourceElement)
{
var masterElementsWithIds = masterElement.XPathSelectElements("//*[@id]");
foreach (var masterElementWithId in masterElementsWithIds)
{
// ReSharper disable PossibleNullReferenceException
var childElementWithSameId = sourceElement.XPathSelectElement("//*[@id='" + masterElementWithId.Attribute("id").Value + "']");
// ReSharper restore PossibleNullReferenceException
if (childElementWithSameId != null)
masterElementWithId.ReplaceWith(childElementWithSameId);
}
return masterElement;
}
开发者ID:joshski,项目名称:neffigy,代码行数:13,代码来源:IdMatchingXElementMerger.cs
示例7: ApplyChanges
static List<string> ApplyChanges(XNode doc, VariableDictionary variables)
{
var changes = new List<string>();
foreach (var variable in variables.GetNames())
{
changes.AddRange(
ReplaceAppSettingOrConnectionString(doc, "//*[local-name()='appSettings']/*[local-name()='add']", "key", variable, "value", variables).Concat(
ReplaceAppSettingOrConnectionString(doc, "//*[local-name()='connectionStrings']/*[local-name()='add']", "name", variable, "connectionString", variables).Concat(
ReplaceStonglyTypeApplicationSetting(doc, "//*[local-name()='applicationSettings']//*[local-name()='setting']", "name", variable, variables))));
}
return changes;
}
开发者ID:bjewell52,项目名称:Calamari,代码行数:13,代码来源:ConfigurationVariablesReplacer.cs
示例8: SelectNode
void SelectNode (XNode n)
{
MonoDevelop.Projects.Dom.DomRegion region = n.Region;
XElement el = n as XElement;
if (el != null && el.IsClosed && el.ClosingTag.Region.End > region.End) {
region.End = el.ClosingTag.Region.End;
}
int s = Editor.GetPositionFromLineColumn (region.Start.Line, region.Start.Column);
int e = Editor.GetPositionFromLineColumn (region.End.Line, region.End.Column);
if (e > s && s > -1)
Editor.Select (s, e);
}
开发者ID:transformersprimeabcxyz,项目名称:monodevelop-1,代码行数:14,代码来源:HtmlEditorExtension.cs
示例9: SelectNode
new void SelectNode (XNode n)
{
MonoDevelop.Projects.Dom.DomRegion region = n.Region;
XElement el = n as XElement;
if (el != null && el.IsClosed && el.ClosingTag.Region.End > region.End) {
region.End = el.ClosingTag.Region.End;
}
int s = Editor.Document.LocationToOffset (region.Start.Line, region.Start.Column );
int e = Editor.Document.LocationToOffset (region.End.Line, region.End.Column);
if (e > s && s > -1)
Editor.SetSelection (s, e);
}
开发者ID:JamesChan,项目名称:monodevelop,代码行数:14,代码来源:HtmlEditorExtension.cs
示例10: TransformEnvironmentNewLineToParagraph
private static object TransformEnvironmentNewLineToParagraph(XNode node)
{
var element = node as XElement;
if (element != null)
{
if (element.Name == W.p)
{
}
return new XElement(element.Name,
element.Attributes(),
element.Nodes().Select(n => TransformEnvironmentNewLineToParagraph(n)));
}
return node;
}
开发者ID:BogdanDamianC,项目名称:Open-Xml-PowerTools,代码行数:16,代码来源:OpenXmlRegex02.cs
示例11: Parse
public static new void Parse(XNode node, DefinitionFile file)
{
UiView.Parse(node, file);
var parser = new DefinitionParser(node);
file["AutomataGrid"] = parser.ParseDelegate("AutomataGrid");
file["EditEnabled"] = parser.ParseBoolean("EditEnabled");
file["Zoom"] = parser.ParseDouble("Zoom");
file["StateToPaint"] = parser.ParseInt("StateToPaint");
file["Colors"] = parser.ParseDelegate("Colors");
file["GridColor"] = parser.ParseColor("GridColor");
}
开发者ID:ebatiano,项目名称:CellularAutomata,代码行数:16,代码来源:AutomataGridView.cs
示例12: CreateGraphFromNode
private AdjacencyGraph<Node, Edge<Node>> CreateGraphFromNode(XDocument xDocument, XNode parent)
{
var graph = new AdjacencyGraph<Node, Edge<Node>>();
var nodes = xDocument.Descendants().Where(x => x.Parent != null && (x.Parent.Parent != null && (x.Parent != null && x.Parent.Parent.Parent == parent)));
var fromList = nodes.Where(x => x.Parent != null && (x.Name.LocalName == "ControlFlow" && x.Parent.Name.LocalName =="FromSimpleRelationships") );
var toList = nodes.Where(x => x.Parent != null && (x.Name.LocalName == "ControlFlow" && x.Parent.Name.LocalName =="ToSimpleRelationships") );
foreach (var fromNode in fromList)
{
var xNode1 = fromNode.Parent.Parent;
string idref = fromNode.Attribute("Idref").Value;
var xNode2 =
toList.Where(x => x.Parent != null && (x.Attribute("Idref").Value.ToString() == idref))
.Select(x => x.Parent.Parent).FirstOrDefault();
if (xNode1 == null || xNode2 == null)
continue;
Node node1 = new Node(xNode1.Attribute("Name").Value, GetNodeType(xNode1));
Node node2 = new Node(xNode2.Attribute("Name").Value, GetNodeType(xNode2));
if (!graph.Vertices.Any(x => x.Name==node1.Name && x.Type==node1.Type))
{
graph.AddVertex(node1);
}
else
{
node1 = graph.Vertices.FirstOrDefault(x => x.Name == node1.Name && x.Type == node1.Type);
}
if (!graph.Vertices.Any(x => x.Name == node2.Name && x.Type == node2.Type))
{
graph.AddVertex(node2);
}
else
{
node2 = graph.Vertices.FirstOrDefault(x => x.Name == node2.Name && x.Type == node2.Type);
}
var newEdge = new Edge<Node>(node1, node2);
if(!graph.ContainsEdge(newEdge))
graph.AddEdge(newEdge);
}
return graph;
}
开发者ID:jkubisiowski,项目名称:Generator,代码行数:47,代码来源:GraphMaker.cs
示例13: XPathElement
//public static XElement XPathElement(XElement xe, string xpath)
public static XElement XPathElement(XNode node, string xpath)
{
if (node == null)
return null;
object xpathResult = node.XPathEvaluate(xpath);
if (xpathResult is IEnumerable)
{
object xpathResult2 = XPathResultGetFirstValue(xpathResult as IEnumerable);
if (xpathResult2 != null)
xpathResult = xpathResult2;
}
if (xpathResult is XElement)
return (XElement)xpathResult;
else
return null;
}
开发者ID:labeuze,项目名称:source,代码行数:18,代码来源:Xml.cs
示例14: XPathValue
//public static string XPathValue(XElement xe, string xpath, string defaultValue = null)
public static string XPathValue(XNode node, string xpath, string defaultValue = null)
{
if (node == null)
return defaultValue;
object xpathResult = node.XPathEvaluate(xpath);
if (xpathResult is IEnumerable)
{
object xpathResult2 = XPathResultGetFirstValue(xpathResult as IEnumerable);
if (xpathResult2 != null)
xpathResult = xpathResult2;
}
string value = XPathResultGetValue(xpathResult);
if (value != null)
return value;
else
return defaultValue;
}
开发者ID:labeuze,项目名称:source,代码行数:19,代码来源:Xml.cs
示例15: LoadAppDomain
private void LoadAppDomain(XNode configRoot)
{
var mde = configRoot.XPathSelectElement("appdomain");
var deleteShadowOnStartup = mde.Attribute("DeleteShadowDirectoryOnStartup")?.Value.ToBoolean() ?? true;
var moduleDirectory = configRoot.XPathSelectElement("appdomain/modules")?.Attribute("Directory")?.Value ??
"ModuleInstances";
var moduleShadowCopyDirectory =
configRoot.XPathSelectElement("appdomain/modules")?.Attribute("ShadowCopyDirectory")?.Value ??
@"ModuleInstances\bin";
var pluginsDirectory = configRoot.XPathSelectElement("appdomain/plugins")?.Attribute("Directory")?.Value ??
"Plugins";
var pluginsShadowCopyDirectory =
configRoot.XPathSelectElement("appdomain/plugins")?.Attribute("ShadowCopyDirectory")?.Value ??
@"Plugins\bin";
AppDomainLoadData = new AppDomainLoadData(deleteShadowOnStartup,
new DynamicLoadingData(pluginsDirectory, pluginsShadowCopyDirectory),
new DynamicLoadingData(moduleDirectory, moduleShadowCopyDirectory));
}
开发者ID:saturn72,项目名称:Saturn72.Core,代码行数:19,代码来源:XmlConfigManager.cs
示例16: ZptXmlLinqElement
/// <summary>
/// Initializes a new instance of the <see cref="CSF.Zpt.DocumentProviders.ZptXmlLinqElement"/> class.
/// </summary>
/// <param name="node">The source XML Node.</param>
/// <param name="sourceFile">Information about the element's source file.</param>
/// <param name="isRoot">Whether or not this is the root element.</param>
/// <param name="isImported">Whether or not this element is imported.</param>
/// <param name="ownerDocument">The ZPT document which owns the element.</param>
public ZptXmlLinqElement(XNode node,
ISourceInfo sourceFile,
IZptDocument ownerDocument,
bool isRoot = false,
bool isImported = false)
: base(sourceFile, isRoot, isImported, ownerDocument)
{
if(node == null)
{
throw new ArgumentNullException(nameof(node));
}
_node = node as XElement;
if(_node.NodeType == XmlNodeType.Document)
{
_node = node.Document.Root;
}
EnforceNodeType("XML", XmlNodeType.Element, _node.NodeType);
}
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:29,代码来源:ZptXmlLinqElement.cs
示例17: Load
public bool Load(String file)
{
if (!System.IO.File.Exists(file))
return false;
this.MapName = System.IO.Path.GetFileNameWithoutExtension(file);
this.Buffer = System.IO.File.ReadAllBytes(file);
this.Header = new BSP_HEADER();
this.Header.Version = System.BitConverter.ToUInt32(this.Buffer, 0);
if (this.Header.Version != 30)
return false;
for (int i = 0; i < this.Header.Lumps.Length; i++)
{
this.Header.Lumps[i] = new BSP_LUMP();
this.Header.Lumps[i].Offset = System.BitConverter.ToUInt32(this.Buffer, sizeof(UInt32) + (i * 2 * sizeof(UInt32)));
this.Header.Lumps[i].Size = System.BitConverter.ToUInt32(this.Buffer, sizeof(UInt32) + (i * 2 * sizeof(UInt32)) + sizeof(UInt32));
}
String ES = System.Text.ASCIIEncoding.ASCII.GetString(this.Buffer, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.ENTITIES].Offset, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.ENTITIES].Size-1);
this.Entities = new XNode();
ParseEntitiesString(ES, this.Entities);
UInt32 NumberTextures = System.BitConverter.ToUInt32(this.Buffer, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.TEXTURES].Offset);
this.Textures = new BSP_TEXTURE_HEADER[NumberTextures];
for (int i = 0; i < this.Textures.Length; i++)
{
this.Textures[i] = new BSP_TEXTURE_HEADER();
Int32 Offset = (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.TEXTURES].Offset + System.BitConverter.ToInt32(this.Buffer, (int)this.Header.Lumps[(int)BSP_LUMP_TYPE.TEXTURES].Offset + sizeof(Int32) + (i * sizeof(UInt32)));
this.Textures[i].Name = System.Text.ASCIIEncoding.ASCII.GetString(this.Buffer, Offset, 16).Split('\0')[0];
this.Textures[i].Width = System.BitConverter.ToUInt32(this.Buffer, Offset + 16);
this.Textures[i].Height = System.BitConverter.ToUInt32(this.Buffer, Offset + 16 + sizeof(UInt32));
for (int j = 0; j < this.Textures[i].Offsets.Length; j++)
this.Textures[i].Offsets[j] = System.BitConverter.ToUInt32(this.Buffer, Offset + 16 + sizeof(UInt32) + sizeof(UInt32) + (j * sizeof(UInt32)));
}
return true;
}
开发者ID:4D4B,项目名称:deBSP,代码行数:40,代码来源:deBSP.cs
示例18: XNodeNavigator
public XNodeNavigator (XNodeNavigator other)
{
this.node = other.node;
this.attr = other.attr;
this.name_table = other.name_table;
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:6,代码来源:XNodeNavigator.cs
示例19: valueOrEmpty
static string valueOrEmpty( XNode node, string xpath )
{
XElement element = node.XPathSelectElement( xpath ) ;
return element != null ? element.Value : string.Empty ;
}
开发者ID:MingMZ,项目名称:treetrim,代码行数:5,代码来源:Settings.cs
示例20: DeepEquals
internal override bool DeepEquals(XNode node)
{
XProcessingInstruction other = node as XProcessingInstruction;
return other != null && target == other.target && data == other.data;
}
开发者ID:ESgarbi,项目名称:corefx,代码行数:5,代码来源:XProcessingInstruction.cs
注:本文中的XNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论