Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can modify XML easily with <a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx" rel="nofollow">LINQ-to-XML</a>. First parse the source document into an <a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx" rel="nofollow"><code>XDocument</code></a> object (you can load files with <a href="http://msdn.microsoft.com/en-us/library/bb343181.aspx" rel="nofollow"><code>.Load</code></a>, or process a string variable containing XML with <a href="http://msdn.microsoft.com/en-us/library/bb345532.aspx" rel="nofollow"><code>.Parse</code></a>):</p> <pre><code>var xdoc = XDocument.Load("/path/to/filename.xml"); </code></pre> <p>You can remove the nodes you don't want by filtering for the specific nodes and using the <a href="http://msdn.microsoft.com/en-us/library/bb357554.aspx" rel="nofollow"><code>.Remove</code></a> extension method (this example removes any element of type <code>&lt;File&gt;</code> that has an attribute <code>version</code> with an exact value of <code>$(Version_Infralution.Common.dll)</code> - you can chain multiple conditions if you want to validate other constraints as well):</p> <pre><code>xdoc.Descendants("File") .Where(x =&gt; x.Attribute("version") != null &amp;&amp; x.Attribute("version").Value == "$(Version_Infralution.Common.dll)") .Remove(); </code></pre> <p>Sample Result:</p> <pre><code>&lt;Files&gt; &lt;File size="73728"&gt;Infralution.RichText.dll&lt;/File&gt; &lt;File version="$(Version_Interop.DSOFile.dll)"&gt;Interop.DSOFile.dll&lt;/File&gt; &lt;File version="$(Version_NLog.dll)"&gt;NLog.dll&lt;/File&gt; &lt;/Files&gt; </code></pre> <hr> <p>You can also alter specific nodes, for example changing the contents of the node, or values of specific attributes, or removing attributes altogether - this example removes the <code>version</code> attribute from any <code>&lt;File&gt;</code> element having a version of <code>"$(Version_Infralution.Common.dll)"</code>:</p> <pre><code>foreach (var xn in xdoc.Descendants("File")) { if (xn.Attribute("version") != null &amp;&amp; xn.Attribute("version").Value == "$(Version_Infralution.Common.dll)") { xn.Attribute("version").Remove(); } } </code></pre> <p>Sample Result:</p> <pre><code>&lt;Files&gt; &lt;File&gt;Infralution.Common.dll&lt;/File&gt; &lt;File&gt;Infralution.Controls.dll&lt;/File&gt; &lt;File&gt;Infralution.Controls.VirtualTree.dll&lt;/File&gt; &lt;File size="73728"&gt;Infralution.RichText.dll&lt;/File&gt; &lt;File version="$(Version_Interop.DSOFile.dll)"&gt;Interop.DSOFile.dll&lt;/File&gt; &lt;File version="$(Version_NLog.dll)"&gt;NLog.dll&lt;/File&gt; &lt;/Files&gt; </code></pre> <hr> <p>Finally, you can save the result to file with <a href="http://msdn.microsoft.com/en-us/library/bb345830.aspx" rel="nofollow"><code>.Save</code></a>:</p> <pre><code>xdoc.Save("/path/to/newfilename.xml"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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