Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read/write nodes and child nodes from xml file in c# maybe using xpath?
    primarykey
    data
    text
    <p>Maybe somebody could help me. I need a two methods.</p> <p>The first should open a xml file and get all nodes with the given parameter ie.: </p> <p>XML file (file.xml):</p> <pre><code>&lt;Menu id="1" Name="myMenu"&gt; &lt;MenuItem Header="Header 1" Name="header1" /&gt; &lt;MenuItem Header="Header 2" Name="header2"&gt; &lt;MenuItem Header="subHeader 2.1" Name="header2_1"&gt; &lt;MenuItem Header="subsubHeader 2.1.1" Name="header2_1_1" /&gt; &lt;/MenuItem&gt; &lt;/MenuItem&gt; &lt;MenuItem Header="Header 3" Name="header3" /&gt; &lt;/Menu&gt; </code></pre> <p>So, now I need to get the values from the xml with a method like this:</p> <pre><code>public static List&lt;string, string&gt;ReadXML(string filename, string node, string[] attributes, bool searchSubNodes); </code></pre> <p>calling method example: <code>ReadXMLValues("file.xml", "MenuItem", new string[] {"Header", "Name"}, true);</code></p> <p>and this would return a list of two strings like:</p> <pre><code>"Header 1", "header1" "Header 2", "header2" "subHeader 2.1", "header2_1" &lt;-- this should be in the list only if searchSubNodes is enabled! "subsubHeader 2.1.1", "header2_1_1" &lt;-- the same for this one!!! "Header 3", "header3" </code></pre> <p>THIS was the reading part and now the writting part:</p> <p>filename is the same like above file.xml. public static void WriteXML(string filename, string node, List attributes);</p> <p>now lets say the file.xml has empty header attributes like this:</p> <pre><code>&lt;Menu id="1" Name="myMenu"&gt; &lt;MenuItem Header="" Name="header1" /&gt; &lt;MenuItem Header="" Name="header2"&gt; </code></pre> <p>And I need to put values into the headers, the finall result should look like this:</p> <pre><code> &lt;Menu id="1" Name="myMenu"&gt; &lt;MenuItem Header="Header 1" Name="header1" /&gt; &lt;MenuItem Header="Header 2" Name="header2"&gt; </code></pre> <p>Is something like this possible??? C# gurus and other people who knows how to do this PLEASE PLEASE help me! I don't know how to do it.</p> <p>Best regards!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload