I want to read and edit the xml file through code. How can I achieve this using XML and Linq? Please help, my xml coding skills are not good.
I want to get the Entity with Name 'new_test' and read/edit the RibbonDiffXml content in that node.
Example XML:
<ImportExportXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Entities>
<Entity>
<Name LocalizedName="test" OriginalName="test">new_test</Name>
<EntityInfo>...</EntityInfo>
..
<RibbonDiffXml>..</RibbonDiffXml>
..
</Entity>
<Entity>
<Name LocalizedName="Account" OriginalName="Account">account</Name>
<EntityInfo>..</EntityInfo>
...
</Entity>
</Entities>
</ImportExportXml>
string xml = @"<CustomActions>
<CustomAction Id='MsCrm.deal.Form.Clone.CustomAction' Location='Mscrm.Form.deal.MainTab.Save.Controls._children' Sequence='46'>
<CommandUIDefinition>
<Button Alt='$LocLabels:MsCrm.deal.Form.Clone.Alt' Command='MsCrm.deal.CloneCommand' Id='MsCrm.deal.Form.Clone' Image32by32='$webresource:new_/image/clone32.png' Image16by16='$webresource:new_/image/clone16.png' LabelText='$LocLabels:MsCrm.deal.Form.Clone.LabelText' Sequence='46' TemplateAlias='o1' ToolTipTitle='$LocLabels:MsCrm.deal.Form.Clone.ToolTipTitle' ToolTipDescription='$LocLabels:MsCrm.deal.Form.Clone.ToolTipDescription' />
</CommandUIDefinition>
</CustomAction>
</CustomActions>";
var ribbon = from entity in document.Root.Element("Entities").Elements()
where entity.Element("Name") != null && entity.Element("Name").Value == entityName
select entity.Element("RibbonDiffXml");
var action = ribbon.Elements("CustomActions").ToList();
action.Add(XElement.Parse(xml));
document.Save(filePath);
I have tried something like this and it doesn't save my changes to the file. However if I use action.Remove() the changes get saved OK. what I am doing wrong ? how can i add elements to the RibbonDiffXml element and save?
