diff --git a/.gitignore b/.gitignore index 648e984..b783ad8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ ################################################################################ /default.config +/default_2019-07-23__12-10-49.config +*.config +/.vs/slnx.sqlite +/.vs/VSWorkspaceState.json +/.vs/ProjectSettings.json +/MoveXMLData/.vs diff --git a/.vs/SebastianProblem/v16/.suo b/.vs/SebastianProblem/v16/.suo new file mode 100644 index 0000000..b4b631c Binary files /dev/null and b/.vs/SebastianProblem/v16/.suo differ diff --git a/MoveXMLData/MoveXMLData.sln b/MoveXMLData/MoveXMLData.sln new file mode 100644 index 0000000..fae57f7 --- /dev/null +++ b/MoveXMLData/MoveXMLData.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.28803.352 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsFormsApp1", "WindowsFormsApp1\WindowsFormsApp1.csproj", "{97198CCC-56C0-4ECD-AFC9-92CC531D57FD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {97198CCC-56C0-4ECD-AFC9-92CC531D57FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97198CCC-56C0-4ECD-AFC9-92CC531D57FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97198CCC-56C0-4ECD-AFC9-92CC531D57FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97198CCC-56C0-4ECD-AFC9-92CC531D57FD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B4B6C059-3DF2-4020-BB41-EEA0D05B33AB} + EndGlobalSection +EndGlobal diff --git a/MoveXMLData/WindowsFormsApp1/Program.cs b/MoveXMLData/WindowsFormsApp1/Program.cs new file mode 100644 index 0000000..ca5979d --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace WindowsFormsApp1 +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new StartShell()); + } + } +} diff --git a/MoveXMLData/WindowsFormsApp1/Properties/AssemblyInfo.cs b/MoveXMLData/WindowsFormsApp1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e64a010 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("WindowsFormsApp1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("WindowsFormsApp1")] +[assembly: AssemblyCopyright("Copyright © 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("97198ccc-56c0-4ecd-afc9-92cc531d57fd")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MoveXMLData/WindowsFormsApp1/Properties/Resources.Designer.cs b/MoveXMLData/WindowsFormsApp1/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b21d543 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsApp1.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("WindowsFormsApp1.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/MoveXMLData/WindowsFormsApp1/Properties/Resources.resx b/MoveXMLData/WindowsFormsApp1/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MoveXMLData/WindowsFormsApp1/Properties/Settings.Designer.cs b/MoveXMLData/WindowsFormsApp1/Properties/Settings.Designer.cs new file mode 100644 index 0000000..438df21 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace WindowsFormsApp1.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/MoveXMLData/WindowsFormsApp1/Properties/Settings.settings b/MoveXMLData/WindowsFormsApp1/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/MoveXMLData/WindowsFormsApp1/StartShell.Designer.cs b/MoveXMLData/WindowsFormsApp1/StartShell.Designer.cs new file mode 100644 index 0000000..92fbce6 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/StartShell.Designer.cs @@ -0,0 +1,176 @@ +namespace WindowsFormsApp1 +{ + partial class StartShell + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.btnFromXml = new System.Windows.Forms.Button(); + this.btnToXml = new System.Windows.Forms.Button(); + this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); + this.lblFromXml = new System.Windows.Forms.Label(); + this.lblToXml = new System.Windows.Forms.Label(); + this.btnStart = new System.Windows.Forms.Button(); + this.lvwResult = new System.Windows.Forms.ListView(); + this.ColumnTagName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.ColumnDataValue = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.ColumnTagXPath = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.txtXPathAnalyse = new System.Windows.Forms.TextBox(); + this.columnTagFound = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.SuspendLayout(); + // + // btnFromXml + // + this.btnFromXml.Location = new System.Drawing.Point(13, 13); + this.btnFromXml.Name = "btnFromXml"; + this.btnFromXml.Size = new System.Drawing.Size(75, 23); + this.btnFromXml.TabIndex = 0; + this.btnFromXml.Text = "FromXml"; + this.btnFromXml.UseVisualStyleBackColor = true; + this.btnFromXml.Click += new System.EventHandler(this.BtnFromXml_Click); + // + // btnToXml + // + this.btnToXml.Location = new System.Drawing.Point(13, 43); + this.btnToXml.Name = "btnToXml"; + this.btnToXml.Size = new System.Drawing.Size(75, 23); + this.btnToXml.TabIndex = 1; + this.btnToXml.Text = "ToXml"; + this.btnToXml.UseVisualStyleBackColor = true; + this.btnToXml.Click += new System.EventHandler(this.BtnToXml_Click); + // + // openFileDialog1 + // + this.openFileDialog1.FileName = "openFileDialog1"; + // + // lblFromXml + // + this.lblFromXml.AutoSize = true; + this.lblFromXml.Location = new System.Drawing.Point(95, 22); + this.lblFromXml.Name = "lblFromXml"; + this.lblFromXml.Size = new System.Drawing.Size(63, 13); + this.lblFromXml.TabIndex = 2; + this.lblFromXml.Text = "fromxmlpath"; + // + // lblToXml + // + this.lblToXml.AutoSize = true; + this.lblToXml.Location = new System.Drawing.Point(95, 52); + this.lblToXml.Name = "lblToXml"; + this.lblToXml.Size = new System.Drawing.Size(52, 13); + this.lblToXml.TabIndex = 3; + this.lblToXml.Text = "toxmlpath"; + // + // btnStart + // + this.btnStart.Location = new System.Drawing.Point(13, 73); + this.btnStart.Name = "btnStart"; + this.btnStart.Size = new System.Drawing.Size(75, 23); + this.btnStart.TabIndex = 4; + this.btnStart.Text = "Start Analyse"; + this.btnStart.UseVisualStyleBackColor = true; + this.btnStart.Click += new System.EventHandler(this.BtnStart_Click); + // + // lvwResult + // + this.lvwResult.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.ColumnTagName, + this.ColumnDataValue, + this.ColumnTagXPath, + this.columnTagFound}); + this.lvwResult.FullRowSelect = true; + this.lvwResult.Location = new System.Drawing.Point(98, 73); + this.lvwResult.MultiSelect = false; + this.lvwResult.Name = "lvwResult"; + this.lvwResult.Size = new System.Drawing.Size(1015, 303); + this.lvwResult.TabIndex = 5; + this.lvwResult.UseCompatibleStateImageBehavior = false; + this.lvwResult.View = System.Windows.Forms.View.Details; + this.lvwResult.Click += new System.EventHandler(this.LvwResult_Click); + // + // ColumnTagName + // + this.ColumnTagName.Text = "Tagname"; + this.ColumnTagName.Width = 200; + // + // ColumnDataValue + // + this.ColumnDataValue.Text = "DataValue"; + this.ColumnDataValue.Width = 200; + // + // ColumnTagXPath + // + this.ColumnTagXPath.Text = "TagXPath"; + this.ColumnTagXPath.Width = 400; + // + // txtXPathAnalyse + // + this.txtXPathAnalyse.Location = new System.Drawing.Point(98, 392); + this.txtXPathAnalyse.Name = "txtXPathAnalyse"; + this.txtXPathAnalyse.Size = new System.Drawing.Size(592, 20); + this.txtXPathAnalyse.TabIndex = 6; + // + // columnTagFound + // + this.columnTagFound.Text = "FoundInSecFile"; + this.columnTagFound.Width = 200; + // + // StartShell + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1171, 450); + this.Controls.Add(this.txtXPathAnalyse); + this.Controls.Add(this.lvwResult); + this.Controls.Add(this.btnStart); + this.Controls.Add(this.lblToXml); + this.Controls.Add(this.lblFromXml); + this.Controls.Add(this.btnToXml); + this.Controls.Add(this.btnFromXml); + this.Name = "StartShell"; + this.Text = "StartShell"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Button btnFromXml; + private System.Windows.Forms.Button btnToXml; + private System.Windows.Forms.OpenFileDialog openFileDialog1; + private System.Windows.Forms.Label lblFromXml; + private System.Windows.Forms.Label lblToXml; + private System.Windows.Forms.Button btnStart; + private System.Windows.Forms.ListView lvwResult; + private System.Windows.Forms.ColumnHeader ColumnTagName; + private System.Windows.Forms.ColumnHeader ColumnDataValue; + private System.Windows.Forms.ColumnHeader ColumnTagXPath; + private System.Windows.Forms.TextBox txtXPathAnalyse; + private System.Windows.Forms.ColumnHeader columnTagFound; + } +} + diff --git a/MoveXMLData/WindowsFormsApp1/StartShell.cs b/MoveXMLData/WindowsFormsApp1/StartShell.cs new file mode 100644 index 0000000..8f3e1a3 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/StartShell.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Configuration; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml; +using System.Xml.Linq; +using System.Xml.XPath; +using System.IO; + +namespace WindowsFormsApp1 +{ + public partial class StartShell : Form + { + XmlDocument xpathTo = null; + + public const string SearchFilter = + "xml files (*.xml)|*.xml|config files (*.config, xml)|*.config|All files (*.*)|*.*"; + private string[] Levels = new string[100]; + public StartShell() + { + InitializeComponent(); + } + + private void BtnFromXml_Click(object sender, EventArgs e) + { + openFileDialog1.Title = "Fetch XML-file keeping new values"; + openFileDialog1.Filter = SearchFilter; + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + lblFromXml.Text = openFileDialog1.FileName; + } + } + + private void BtnToXml_Click(object sender, EventArgs e) + { + openFileDialog1.Title = "Fetch XML-file to be updated"; + openFileDialog1.Filter = SearchFilter; + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + lblToXml.Text = openFileDialog1.FileName; + } + } + + private void BtnStart_Click(object sender, EventArgs e) + { + // XML-document analysed + + XmlDocument xnode = new XmlDocument(); + xnode.Load(lblFromXml.Text); + + + if (lblToXml.Text != "toxmlpath") + { + // XML-document for receiving file + + xpathTo = new XmlDocument(); + xpathTo.Load(lblToXml.Text); + } + + + lvwResult.Items.Clear(); + Process(xnode); + + // Saves to temporary file + xpathTo.Save("abc.xml"); + + // Move temporary file to original directory + + FileInfo fi = new FileInfo(lblToXml.Text); + var actDir = fi.DirectoryName; + var createdFile = File.ReadAllBytes("abc.xml"); + var fName = actDir + "\\default_" + DateTime.Now.ToShortDateString()+"__" + DateTime.Now.ToLongTimeString().Replace(":","-") + ".config"; + File.WriteAllBytes(fName,createdFile); + File.Delete("abc.xml"); + } + + void Process(XmlNode node) + { + // Processing is a recurring process + Process(node, 0); + } + + void Process(XmlNode node, int level) + { + + if (node.NodeType == XmlNodeType.Text) + { + ListViewItem lviResult = new ListViewItem(); + lviResult.Text = node.ParentNode.LocalName; + lviResult.SubItems.Add(node.Value); + + // Find XPath for current node + var xPath = GetXPathToNode(node); + + // Routine for XPath creates bad end on text-nodes / chenges to something seems working + if (xPath.Trim().Substring(xPath.Trim().Length - 9) == "/#text[1]") + { + xPath = xPath.Substring(0, xPath.Trim().Length - 9); + xPath = xPath + "/text()"; + } + + // Put data into ListView + + lviResult.SubItems.Add(xPath); + if (lblToXml.Text != "toxmlpath") + { + XmlNode searchedField = xpathTo.SelectSingleNode(xPath); + if (searchedField != null) + { + lviResult.SubItems.Add(searchedField.InnerText); + searchedField.Value = node.Value; + } + else + { + searchedField = xpathTo.SelectSingleNode(xPath.Substring(0, xPath.Trim().Length-7)); + if (searchedField.OuterXml != "") + { + lviResult.SubItems.Add(searchedField.OuterXml); + XmlElement elemSearchfield = (XmlElement) searchedField; + if (elemSearchfield.IsEmpty) + { + elemSearchfield.InnerXml = node.Value; + } + } + else lviResult.SubItems.Add("saknas!"); + } + } + + + + lvwResult.Items.Add(lviResult); + } + + foreach (XmlNode child in node.ChildNodes) + { + Process(child, level + 1); + } + } + + /// + /// Gets the X-Path to a given Node + /// + /// The Node to get the X-Path from + /// The X-Path of the Node + public string GetXPathToNode(XmlNode node) + { + if (node.NodeType == XmlNodeType.Attribute) + { + // attributes have an OwnerElement, not a ParentNode; also they have + // to be matched by name, not found by position + return String.Format("{0}/@{1}", GetXPathToNode(((XmlAttribute)node).OwnerElement), node.Name); + } + if (node.ParentNode == null) + { + // the only node with no parent is the root node, which has no path + return ""; + } + + // Get the Index + int indexInParent = 1; + XmlNode siblingNode = node.PreviousSibling; + // Loop thru all Siblings + while (siblingNode != null) + { + // Increase the Index if the Sibling has the same Name + if (siblingNode.Name == node.Name) + { + indexInParent++; + } + siblingNode = siblingNode.PreviousSibling; + } + + // the path to a node is the path to its parent, plus "/node()[n]", where n is its position among its siblings. + return String.Format("{0}/{1}[{2}]", GetXPathToNode(node.ParentNode), node.Name, indexInParent); + } + + + private void LvwResult_Click(object sender, EventArgs e) + { + var firstSelectedItem = lvwResult.SelectedItems[0]; + var xpath = firstSelectedItem.SubItems[2].Text; + if (xpath.Trim().Substring(xpath.Trim().Length - 9) == "/#text[1]") + { + txtXPathAnalyse.Text = xpath.Substring(0, xpath.Trim().Length - 9); + } + else + { + txtXPathAnalyse.Text = xpath; + } + } + } + +} diff --git a/MoveXMLData/WindowsFormsApp1/StartShell.resx b/MoveXMLData/WindowsFormsApp1/StartShell.resx new file mode 100644 index 0000000..9bad2f5 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/StartShell.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/MoveXMLData/WindowsFormsApp1/WindowsFormsApp1.csproj b/MoveXMLData/WindowsFormsApp1/WindowsFormsApp1.csproj new file mode 100644 index 0000000..913e4e8 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/WindowsFormsApp1.csproj @@ -0,0 +1,84 @@ + + + + + Debug + AnyCPU + {97198CCC-56C0-4ECD-AFC9-92CC531D57FD} + WinExe + WindowsFormsApp1 + WindowsFormsApp1 + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + StartShell.cs + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + StartShell.cs + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + \ No newline at end of file diff --git a/MoveXMLData/WindowsFormsApp1/XpathUpd.cs b/MoveXMLData/WindowsFormsApp1/XpathUpd.cs new file mode 100644 index 0000000..463ea9f --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/XpathUpd.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; + +namespace WindowsFormsApp1 +{ + public class XpathUpd + { + public void testXpathModifying() + { + // text xml + var xml = @" + + + BSE + + + "; + + XmlDocument xmld = new XmlDocument(); + + XmlNamespaceManager nsmgr; // this will hold our namespaces with their prefixes + xmld.Load(GetReader(xml, out nsmgr)); // xml can also be your file + + // we are going to find a text node, hence cast to XmlText + var name2 = (XmlText)xmld.SelectSingleNode( + "/Data/Inputs/a:ImageInput/a:Name[.='BSE']/text()", + nsmgr); // here is the namespace manager so it knows what a is + if (name2 != null) + { + //name2.SetAttribute("a:Name", "{{16}}"); + name2.Value = "{{16}}"; + } + + string AmmendedFile = @"C:\ProgramData\Oxford Instruments NanoAnalysis\XXXX NewXMLReader\Xpath_Mics_Sim.xml"; + xmld.Save(AmmendedFile); + } + + // Creates a reader and outputs a namespacemanager that fits for the missing namespace prefixes + XmlReader GetReader(string xml, out XmlNamespaceManager nsmgr) + { + // code example taken from + // https://blogs.msdn.microsoft.com/runeetv/2009/02/12/undeclared-namespace-in-xml-eg-xsi-is-an-undeclared-namespace/ + // from author runeetv and https://blogs.msdn.microsoft.com/runeetv/author/runeetvashisht/ + + NameTable nt = new NameTable(); + // add missing namespace prefixes + nsmgr = new XmlNamespaceManager(nt); + nsmgr.AddNamespace("a", "urn:why-was-this-left-out?"); + + XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None); + XmlReaderSettings xset = new XmlReaderSettings(); + xset.ConformanceLevel = ConformanceLevel.Fragment; + + // return XmlReader.Create(xml, xset, context); // use this if you want xml to be a filepath + return XmlReader.Create(new StringReader(xml), xset, context); + } + + } +} diff --git a/MoveXMLData/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.exe b/MoveXMLData/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.exe new file mode 100644 index 0000000..33895b2 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.exe differ diff --git a/MoveXMLData/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.pdb b/MoveXMLData/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.pdb new file mode 100644 index 0000000..f9e44b2 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/bin/Debug/WindowsFormsApp1.pdb differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/DesignTimeResolveAssemblyReferences.cache b/MoveXMLData/WindowsFormsApp1/obj/Debug/DesignTimeResolveAssemblyReferences.cache new file mode 100644 index 0000000..3f43d9d Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/DesignTimeResolveAssemblyReferences.cache differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/MoveXMLData/WindowsFormsApp1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..bc28aa9 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.Properties.Resources.resources b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.Properties.Resources.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.Properties.Resources.resources differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.StartShell.resources b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.StartShell.resources new file mode 100644 index 0000000..6c05a97 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.StartShell.resources differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.CoreCompileInputs.cache b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..f015d1d --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +6c5f03965c3e08c229aab2472d3cf7433561affc diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.FileListAbsolute.txt b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..e8cd664 --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.FileListAbsolute.txt @@ -0,0 +1,20 @@ +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe.config +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.pdb +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.csprojAssemblyReference.cache +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.Properties.Resources.resources +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.StartShell.resources +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.csproj.GenerateResource.cache +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.csproj.CoreCompileInputs.cache +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.exe +D:\SebastianProblem\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.pdb +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe.config +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.exe +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\bin\Debug\WindowsFormsApp1.pdb +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.csprojAssemblyReference.cache +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.Properties.Resources.resources +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.StartShell.resources +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.csproj.GenerateResource.cache +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.csproj.CoreCompileInputs.cache +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.exe +D:\Sebastian\ConfigFix\MoveXMLData\WindowsFormsApp1\obj\Debug\WindowsFormsApp1.pdb diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.GenerateResource.cache b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.GenerateResource.cache new file mode 100644 index 0000000..4c4fe7d Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csproj.GenerateResource.cache differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csprojAssemblyReference.cache b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csprojAssemblyReference.cache new file mode 100644 index 0000000..04fa867 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.csprojAssemblyReference.cache differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.exe b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.exe new file mode 100644 index 0000000..33895b2 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.exe differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.pdb b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.pdb new file mode 100644 index 0000000..f9e44b2 Binary files /dev/null and b/MoveXMLData/WindowsFormsApp1/obj/Debug/WindowsFormsApp1.pdb differ diff --git a/MoveXMLData/WindowsFormsApp1/obj/Release/WindowsFormsApp1.csproj.CoreCompileInputs.cache b/MoveXMLData/WindowsFormsApp1/obj/Release/WindowsFormsApp1.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..4f6909e --- /dev/null +++ b/MoveXMLData/WindowsFormsApp1/obj/Release/WindowsFormsApp1.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +64189f8a8db434f4fb2fa6b7a4d692e3501df3ab