Note that there are some explanatory texts on larger screens.

plurals
  1. POlinq to xml how to move one element from one xml to another
    primarykey
    data
    text
    <p>i am facing one problem i have two xml files.</p> <p><strong>Plugins.xml</strong></p> <pre><code>&lt;SolutionProfile xmlns="http://schemas.microsoft.com/pag/cab-profile"&gt; &lt;Modules&gt; &lt;ModuleInfo AssemblyFile="PluginXXX.dll" /&gt; &lt;/Modules&gt; &lt;/SolutionProfile&gt; </code></pre> <p><strong>ProfileCatalog.xml</strong></p> <pre><code>&lt;SolutionProfile xmlns="http://schemas.microsoft.com/pag/cab-profile/2.0"&gt; &lt;Section Name="Services"&gt; &lt;Modules&gt; &lt;ModuleInfo AssemblyFile="Module.dll" /&gt; &lt;/Modules&gt; &lt;/Section&gt; &lt;Section Name="Apps"&gt; &lt;Dependencies&gt; &lt;Dependency Name="Services" /&gt; &lt;/Dependencies&gt; &lt;Modules&gt; &lt;ModuleInfo AssemblyFile="PluginABC.dll" &gt; &lt;/Modules&gt; &lt;/Section&gt; &lt;/SolutionProfile&gt; </code></pre> <p>i wants to move PluginXXX.dll from Plugins.xml to ProfileCatalog.xml. </p> <p>the code i used is as </p> <pre><code>public static void PluginLoaded(string pluginName) { XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Indent = true; XDocument pluginDoc = XDocument.Load("Plugins.xml"); XDocument profileCatalogDoc = XDocument.Load("ProfileCatalog.xml"); XmlWriter pluginDocXmlWriter = XmlWriter.Create("Plugins.xml", settings); XmlWriter profileCatalogDocXmlWriter = XmlWriter.Create("ProfileCatalog.xml", settings); XNamespace ns = "http://schemas.microsoft.com/pag/cab-profile"; var res = from plugin in pluginDoc.Descendants(ns + "ModuleInfo") where plugin.Attribute("AssemblyFile").Value == pluginName select plugin; // save the plugin to remove XElement pluginToMove = res.FirstOrDefault(); //remove from xml res.FirstOrDefault().Remove(); // save xml back pluginDoc.Save(pluginDocXmlWriter); XNamespace pns = "http://schemas.microsoft.com/pag/cab-profile/2.0"; var pRes = ((from pcPlugin in profileCatalogDoc.Descendants(pns + "Modules") select pcPlugin).Skip(1).Take(1)).FirstOrDefault(); pRes.Add(pluginToMove); profileCatalogDoc.Save(profileCatalogDocXmlWriter); //TODO : move the plugin name from Plugins.xml to ProfileCatalog.xml profileCatalogDocXmlWriter.Close(); pluginDocXmlWriter.Close(); } </code></pre> <p><strong>NOTE</strong> there is xmlns difference between both files. when i move the node from Plugins.xml to ProfileCatalog.xml it adds the element as</p> <pre><code>&lt;ModuleInfo AssemblyFile="PluginXXX.dll" xmlns="http://schemas.microsoft.com/pag/cab-profile" /&gt; </code></pre> <p>I want to remove this xmlns before adding to this file.</p> <p>kindly give me a solution.</p>
    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.
 

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