【发布时间】:2019-01-28 21:49:36
【问题描述】:
我正在努力序列化以下 XML 代码...
<Activity mc:Ignorable="sap sap2010 sads" x:Class="Main"
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sco="clr-namespace:System.Collections.ObjectModel;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<TextExpression.NamespacesForImplementation>
<sco:Collection x:TypeArguments="x:String">
<x:String>System.Activities</x:String>
<x:String>System.Activities.Statements</x:String>
<x:String>System.Activities.Expressions</x:String>
<x:String>System.Activities.Validation</x:String>
<x:String>System.Activities.XamlIntegration</x:String>
<x:String>Microsoft.VisualBasic</x:String>
<x:String>Microsoft.VisualBasic.Activities</x:String>
<x:String>System</x:String>
<x:String>System.Collections</x:String>
<x:String>System.Collections.Generic</x:String>
<x:String>System.Data</x:String>
<x:String>System.Diagnostics</x:String>
<x:String>System.Drawing</x:String>
<x:String>System.IO</x:String>
<x:String>System.Linq</x:String>
<x:String>System.Net.Mail</x:String>
<x:String>System.Xml</x:String>
<x:String>System.Xml.Linq</x:String>
<x:String>UiPath.Core</x:String>
<x:String>System.Windows.Markup</x:String>
<x:String>UiPath.Core.Activities</x:String>
</sco:Collection>
</TextExpression.NamespacesForImplementation>
</Activity>
我觉得我已经在各种属性上尝试了 [XmlArray] 和 [XmlArrayItem] 的所有组合,但我似乎可以同时捕获 TypeArguments 属性和字符串值列表。我也不确定我需要制作哪些课程才能完成这项工作。有什么建议吗?
注意 我也尝试过使用“特殊粘贴”选项来生成类结构,但是在序列化并立即反序列化之后,输出的 xml 文件的结构不同。
【问题讨论】:
-
你有 Visual Studio 2012+ 吗?如果是这样,请尝试this answer 中的方法 2。如果没有,请尝试方法 1 :)
-
@LewsTherin 我这样做了,我也试过了。由于某种原因,似乎完全忽略了 XML 文件的这一部分!因此,我不得不手动尝试。
-
您是否通过 XML 验证器运行 XML?如果 XML 无效,这两种方法将无法正常工作。
-
你能展示更多你的 xml(比如命名空间,并使其成为有效的 XML)吗?这样,我们可以尝试重现您的问题。
-
@Flydog57 当然可以。我会将它添加到原始帖子中。我还验证了这是有效的 xml。
标签: c# xml serialization xmlserializer