Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# bbonDiffXml有子节点,我正在尝试向其中添加节点。但是,我的更改不会被保存。var ribbon=来自document.Root.Element(“实体”).Elements()中的实体,其中entity.Element(“名称”)!=null&&_C#_Xml_Linq - Fatal编程技术网

C# bbonDiffXml有子节点,我正在尝试向其中添加节点。但是,我的更改不会被保存。var ribbon=来自document.Root.Element(“实体”).Elements()中的实体,其中entity.Element(“名称”)!=null&&

C# bbonDiffXml有子节点,我正在尝试向其中添加节点。但是,我的更改不会被保存。var ribbon=来自document.Root.Element(“实体”).Elements()中的实体,其中entity.Element(“名称”)!=null&&,c#,xml,linq,C#,Xml,Linq,bbonDiffXml有子节点,我正在尝试向其中添加节点。但是,我的更改不会被保存。var ribbon=来自document.Root.Element(“实体”).Elements()中的实体,其中entity.Element(“名称”)!=null&&entity.Element(“Name”).Value==entityName选择实体.Element(“RibbonDiffXml”);var action=ribbon.Elements(“CustomActions”).ToList()


bbonDiffXml有子节点,我正在尝试向其中添加节点。但是,我的更改不会被保存。var ribbon=来自document.Root.Element(“实体”).Elements()中的实体,其中entity.Element(“名称”)!=null&&entity.Element(“Name”).Value==entityName选择实体.Element(“RibbonDiffXml”);var action=ribbon.Elements(“CustomActions”).ToList();请使用注释中的代码和完整的xml(包含RibbonDiffXml的内容)更新您的问题,我在下面发布了代码。有机会的时候请看一看
<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);
XDocument document = XDocument.Parse(Properties.Resources.XML);
if (document.Root != null)
{
    IEnumerable<string> elements = 
    (from entity in document.Root.Element("Entities").Elements()
    let name = entity.Element("Name")
    where name != null && name.Value == "new_test"
    let ribbonDiffXml = entity.Element("RibbonDiffXml")
    where ribbonDiffXml != null
    select ribbonDiffXml.Value);
}
foreach (XElement ribbonDiffXml in from entity in document.Root.Element("Entities").Elements() 
                                   let name = entity.Element("Name") 
                                   where name != null && name.Value == "new_test" 
                                   select entity.Element("RibbonDiffXml") 
                                   into ribbonDiffXml 
                                   where ribbonDiffXml != null select ribbonDiffXml)
                {
                    ribbonDiffXml.Value = "Changed RibbonDiffXml";
                }
document.Save("PATH OR STREAM OR ...");
String s = @"<ImportExportXml><Entities><Entity><Name>new_test</Name><EntityInfo></EntityInfo><RibbonDiffXml></RibbonDiffXml></Entity></Entities></ImportExportXml>";

var xdoc = XElement.Parse(s);
var f = (from x in xdoc.DescendantsAndSelf(@"Entities")
        where x.Element("Entity").Element("Name").Value == "new_test"
        select x.Element("Entity").Element("RibbonDiffXml"));

foreach(var y in f)
{
    y.Value = "Hello World";
}