hi. i am facing one problem i have two xml files.
Plugins.xml
<SolutionProfile xmlns="http://schemas.microsoft.com/pag/cab-profile">
<Modules>
<ModuleInfo AssemblyFile="PluginXXX.dll" />
</Modules>
</SolutionProfile>
ProfileCatalog.xml
<SolutionProfile xmlns="http://schemas.microsoft.com/pag/cab-profile/2.0">
<Section Name="Services">
<Modules>
<ModuleInfo AssemblyFile="Module.dll" />
</Modules>
</Section>
<Section Name="Apps">
<Dependencies>
<Dependency Name="Services" />
</Dependencies>
<Modules>
<ModuleInfo AssemblyFile="PluginABC.dll" >
</Modules>
</Section>
</SolutionProfile>
i wants to move PluginXXX.dll from Plugins.xml to ProfileCatalog.xml.
the code i used is as
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();
}
NOTE there is xmlns difference between both files. when i move the node from Plugins.xml to ProfileCatalog.xml it adds the element as
<ModuleInfo AssemblyFile="PluginXXX.dll" xmlns="http://schemas.microsoft.com/pag/cab-profile" />
I want to remove this xmlns before adding to this file.
kindly give me a solution.