Reputation: 1587
I am trying to get the workflow tag using XDocument class but it is given me below mentioned exception :
The ':' character, hexadecimal value 0x3A, cannot be included in a name.
I have also tried using namespace but no positive result achieved.
XML:
<?xml version="1.0" encoding="utf-16"?>
<Activity x:Class="XrmWorkflow75328ae32924499d972dd68053611740" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:mxswa="clr-namespace:Microsoft.Xrm.Sdk.Workflow.Activities;assembly=Microsoft.Xrm.Sdk.Workflow, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" xmlns:s="clr-namespace:System;assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" xmlns:this="clr-namespace:" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<mxswa:Workflow>
<mxswa:ActivityReference AssemblyQualifiedName="Microsoft.Crm.Workflow.Activities.ConditionSequence, Microsoft.Crm.Workflow, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" DisplayName="ConditionStep1: name">
</mxswa:ActivityReference>
</mxswa:Workflow>
</Activity>
CODE :
string strXml = File.ReadAllText(@"../../XMLFile1.xml");
XDocument xdoc = XDocument.Parse(strXml);
XNamespace xmlns = "clr-namespace:Microsoft.Xrm.Sdk.Workflow.Activities;assembly=Microsoft.Xrm.Sdk.Workflow, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
var results = from node in xdoc.Descendants( xmlns + "Workflow")
select node;
results is always null.
Upvotes: 0
Views: 879
Reputation: 11367
I am trying to get the workflow tag
As @Sergey Berezovskiy mentioned you need to use the XNamespace
.
Here is the complete working example.
var xml = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Activity x:Class=""XrmWorkflow75328ae32924499d972dd68053611740"" xmlns=""http://schemas.microsoft.com/netfx/2009/xaml/activities"" xmlns:mxswa=""clr-namespace:Microsoft.Xrm.Sdk.Workflow.Activities;assembly=Microsoft.Xrm.Sdk.Workflow, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" xmlns:s=""clr-namespace:System;assembly=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"" xmlns:this=""clr-namespace:"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<mxswa:Workflow>
<mxswa:ActivityReference AssemblyQualifiedName=""Microsoft.Crm.Workflow.Activities.ConditionSequence, Microsoft.Crm.Workflow, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"" DisplayName=""ConditionStep1: name"" />
</mxswa:Workflow>
</Activity>";
XDocument xdoc = XDocument.Parse(xml);
XNamespace xnamespace = "clr-namespace:Microsoft.Xrm.Sdk.Workflow.Activities;assembly=Microsoft.Xrm.Sdk.Workflow, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
var nodes = xdoc.Descendants(xnamespace + "Workflow");
Upvotes: 2
Reputation: 236248
Here is correct way of using namespace in element name:
xdoc.Descendants(xmlns + "ActivityReference.Arguments")
I.e. its XNamespace
plus local name string.
Note: there is no mxswa:ActivityReference.Arguments
node in your sample xml and your mxswa:ActivityReference
do not have closing tag.
Upvotes: 2