Forums - C# Corner

Forum guidelines
Pradeep Yadav

Pradeep Yadav

  • 374
  • 4.8k
  • 773.3k

Add Xelement to exting element

Jun 20 2019 8:26 AM
Hi,
I amd trying to add element to exiting XElement.
Please help me
I am getting below element
<Sequence mc:Ignorable="sap sads" sap:VirtualizedContainerService.HintSize="200,139" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:ln="clr-namespace:DGSL.TruBot.ActivityLibrary;assembly=DGSL.TruBot.ActivityLibrary"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<dta:OpenBrowser BrowserType="CHROME" />
</Sequence>
And I want to add  below element to Sequence,
 
<ln:OpenBrowser Option ="None" TestCode="False"/> 
 
Final output should be 
 
<Sequence mc:Ignorable="sap sads" sap:VirtualizedContainerService.HintSize="200,139" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:ln="clr-namespace:DGSL.TruBot.ActivityLibrary;assembly=DGSL.TruBot.ActivityLibrary"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mva="clr-namespace:Microsoft.VisualBasic.Activities;assembly=System.Activities"
xmlns:sads="http://schemas.microsoft.com/netfx/2010/xaml/activities/debugger"
xmlns:sap="http://schemas.microsoft.com/netfx/2009/xaml/activities/presentation"
xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<sap:WorkflowViewStateService.ViewState>
<scg:Dictionary x:TypeArguments="x:String, x:Object">
<x:Boolean x:Key="IsExpanded">True</x:Boolean>
</scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>
<dta:OpenBrowser BrowserType="CHROME" />
<ln:OpenBrowser Option ="None" TestCode="False"/>
</Sequence>
 
 
I have used 
 
 
string DefaultActivityString = "OpenBrowser BrowserType =\"CHROME\"";
xmlnsAliasName ="ln"; 
 
public XElement GetXAML(string xmlnsAliasName)
{
return XElement.Parse(@"<" + xmlnsAliasName + ":" + DefaultActivityString + "/>");
}
however it is giving me error for invalid character 
 
Please help me to fix this.
 
Regards,
Pradeep