Provides convenience methods for changing one or more individual
text nodes in an XML file.
System Object CleanCode.Xml NodeWranglerNamespace: CleanCode.XmlAssembly: CleanCode (in CleanCode.dll) Version: 1.2.3.0 (1.2.03)
public class NodeWrangler
public class NodeWrangler
Public Class NodeWrangler
Public Class NodeWrangler
public ref class NodeWrangler
public ref class NodeWrangler
To use, create an object, specifying an XML file, then load the file.
NodeWrangler nodeWrangler = new NodeWrangler(filename);
if (!nodeWrangler.LoadXml())
{ return filename + ": cannot load"; }
NodeWrangler nodeWrangler = new NodeWrangler(filename);
if (!nodeWrangler.LoadXml())
{ return filename + ": cannot load"; }
string oldStuff = nodeWrangler.ReadNode(MY_NODE);
if (oldStuff == null)
{ return filename + ": " + MY_NODE + ": cannot locate node"; }
if (oldStuff.Equals(newStuff))
{ return "oldStuff already set to [" + newStuff + "]"; }
if (!nodeWrangler.UpdateNode(MY_NODE, newStuff))
{ return filename + ": " + MY_NODE + ": cannot locate node"; }
string oldStuff = nodeWrangler.ReadNode(MY_NODE);
if (oldStuff == null)
{ return filename + ": " + MY_NODE + ": cannot locate node"; }
if (oldStuff.Equals(newStuff))
{ return "oldStuff already set to [" + newStuff + "]"; }
if (!nodeWrangler.UpdateNode(MY_NODE, newStuff))
{ return filename + ": " + MY_NODE + ": cannot locate node"; }
if (!nodeWrangler.WriteXml())
{ return filename + ": cannot write"; }
if (!nodeWrangler.WriteXml())
{ return filename + ": cannot write"; }
Then, make any changes for each node of interest. In this code
fragment, we read a text node, see if it already matches what we
want to change it to, and if not, change it.
Finally, save the changes you have made:
Since CleanCode 0.9.07.