Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lazy XML selection
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Xml; namespace Rextester { public class Program { public static void Main(string[] args) { { var doc = CreateDocument(); var selection = doc.SelectNodes("root/elem[@n < 4]"); PrintAndModify(selection); } { var doc = CreateDocument(); var selection = doc.SelectNodes("root/elem[@n < 4]"); Console.WriteLine("Selected " + selection.Count + " elements"); PrintAndModify(selection); } } private static XmlDocument CreateDocument() { var doc = new XmlDocument(); var root = doc.CreateElement("root"); doc.AppendChild(root); for (var i = 0; i < 10; i++) { var elem = doc.CreateElement("elem"); elem.SetAttribute("n", i.ToString()); root.AppendChild(elem); } return doc; } private static void PrintAndModify(XmlNodeList xnl) { var i = 0; foreach (XmlElement elem in xnl){ Console.WriteLine("Seen element: " + elem.OuterXml); var next = elem.NextSibling; if (next == null) { continue; } var nextNext = (XmlElement)next.NextSibling; if (nextNext != null) { nextNext.SetAttribute("n", elem.GetAttribute("n")); } } } } }
run
|
edit
|
history
|
help
1
Herencias
6.4 Parallelism: threads and events
Nested Namespace
Expression Tree
Integers Array manipulation examples
IMT
if Two Words Are Anagrams of Each Other
Reverse Array
A
asdfrgthyjuhtgrfed