Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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# 使用xml属性名称反序列化->;财产_C#_Serialization_Deserialization - Fatal编程技术网

C# 使用xml属性名称反序列化->;财产

C# 使用xml属性名称反序列化->;财产,c#,serialization,deserialization,C#,Serialization,Deserialization,假设我有以下XML <doc> <float name="score">7.8753223</float> <str name="author">asdadsad</str> <str name="body">...</str> <str name="category">haelth-safety</str> </doc> 如何告诉序列化程序使

假设我有以下XML

<doc>
    <float name="score">7.8753223</float>
    <str name="author">asdadsad</str>
    <str name="body">...</str>
    <str name="category">haelth-safety</str>
</doc>

如何告诉序列化程序使用xml属性名称将数据映射到c#属性?

对于指定的xml格式,无法使用声明式(属性化)序列化。如果要使用声明式序列化,请将格式更改为以下格式:

<doc>
    <score>7.8889798</score>
    <author>agfdfg</author>
    <body>...</body>
    <category>haleth safet</category>
</doc>

7.8889798
agfdfg
...
海利斯·萨菲特

并使用XmlElementAttribute为序列化的属性指定相应的元素名称。

XML来自Solr,因此我无法控制:/然后您必须自定义序列化。谷歌搜索
IXmlSerializable
。可能重复
<doc>
    <score>7.8889798</score>
    <author>agfdfg</author>
    <body>...</body>
    <category>haleth safet</category>
</doc>