当前位置: 首页>>代码示例>>C#>>正文


C# XNode类代码示例

本文整理汇总了C#中XNode的典型用法代码示例。如果您正苦于以下问题:C# XNode类的具体用法?C# XNode怎么用?C# XNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XNode类属于命名空间,在下文中一共展示了XNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的XNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。