Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I'm understanding you correctly, you can use <code>ImportNode</code> to add data from one xml to another.</p> <p>Something like this.</p> <pre><code>XmlDocument doc1 = new XmlDocument(); doc1.Load("config.xml"); XmlDocument doc2 = new XmlDocument(); doc2.Load("configtemplate.xml"); XmlNode doc1root, doc2root, importNode; doc1root = doc1.DocumentElement; doc2root = doc2.DocumentElement; foreach(XmlNode node in doc2root.ChildNodes) { importNode = doc1root.OwnerDocument.ImportNode(node, true); doc1root.AppendChild(importNode); } </code></pre> <p>This way it import <code>&lt;Database&gt;</code>, <code>&lt;Services&gt;</code>, <code>&lt;Options&gt;</code> from <strong>configtemplate.xml</strong> into <strong>config.xml</strong> under <code>&lt;config&gt;</code></p> <p>In your case, you will need to know the tag you want to import from and to, which is not specified in your example.</p> <p><strong>Explanation:</strong></p> <p><code>doc1root</code> is the root tag of <strong>config.xml</strong>, which is <code>&lt;config&gt;</code></p> <p><code>doc2root</code> is the root tag of <strong>configtemplate.xml</strong>, which is <code>&lt;config&gt;</code></p> <p>in the <code>foreach</code> loop, you are looping through each child node of <code>doc2root</code> (which are <code>&lt;Database&gt;</code>, <code>&lt;Services&gt;</code>, and <code>&lt;Options&gt;</code>), and adding each child node to be a child of <code>doc1root</code></p> <p>With the above code what you will get is a new <strong>config.xml</strong> that looks like this.</p> <pre><code>&lt;config&gt; &lt;Database&gt; &lt;DataType&gt;1&lt;/DataType&gt; &lt;ServerName&gt;192.168.50.80&lt;/ServerName&gt; // add information here supplied by the configtemplate.xml &lt;/Database&gt; &lt;Services&gt; &lt;Wash&gt;1&lt;/Wash&gt; // add information here supplied by the configtemplate.xml &lt;/Services&gt; &lt;Options&gt; &lt;TaxRate&gt;8.125&lt;/TaxRate&gt; &lt;AskForZipcode&gt;0&lt;/AskForZipcode&gt; // add information here supplied by the configtemplate.xml &lt;/Options&gt; //below are from configtemplate.xml &lt;Database&gt; &lt;DataType&gt;1&lt;/DataType&gt; &lt;ServerName&gt;192.168.50.80&lt;/ServerName&gt; // add all lines below to config.xml &lt;DatabaseName&gt;TestDB&lt;/DatabaseName&gt; &lt;/Database&gt; &lt;Services&gt; &lt;Wash&gt;1&lt;/Wash&gt; // add all lines below to config.xmlxml &lt;Greeter&gt;0&lt;/Greeter&gt; &lt;/Services&gt; &lt;Options&gt; &lt;TaxRate&gt;8.125&lt;/TaxRate&gt; &lt;AskForZipcode&gt;0&lt;/AskForZipcode&gt; // add all lines below to config.xml &lt;AutoSave&gt;1&lt;/AutoSave&gt; &lt;/Options&gt; &lt;/config&gt; </code></pre> <p>By the way, the proper way of commenting in xml is the same as html, which is <code>&lt;!--comment--&gt;</code></p>
 

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