Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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# 如何使用多个cdata xml c编写/设置子节点#_C#_Xml_String_Cdata - Fatal编程技术网

C# 如何使用多个cdata xml c编写/设置子节点#

C# 如何使用多个cdata xml c编写/设置子节点#,c#,xml,string,cdata,C#,Xml,String,Cdata,我尝试生成如下所示的XML <?xml version="1.0" encoding="UTF-8"?> <movie> <title><![CDATA[Con Air]]></title> <plot><![CDATA[When the government puts all its rotten criminal eggs in one airborne basket, it's asking for troubl

我尝试生成如下所示的XML

<?xml version="1.0" encoding="UTF-8"?>
<movie>
<title><![CDATA[Con Air]]></title>
<plot><![CDATA[When the government puts all its rotten criminal eggs in one airborne basket, it's asking for trouble. Before you can say, "Pass the barf bag," the crooks control the plane, led by creepy Cyrus "The Virus" Grissom. Watching his every move is the just-released Cameron Poe, who'd rather reunite with his family. The action climaxes with an incredible crash sequence in Las Vegas.]]></plot>
<tagline><![CDATA[They were deadly on the ground; Now they have wings]]></tagline>
<year>1997</year>
<id>tt0118880</id>
<rating>65</rating>
<votes>93</votes>
<budget>75000000</budget>
<revenue>224012234</revenue>
<company><![CDATA[Touchstone Pictures]]></company>
<genre>
<name><![CDATA[Action]]></name>
<name><![CDATA[Adventure]]></name>
<name><![CDATA[Thriller]]></name>
</genre>
</movie>
<?xml version="1.0" encoding="utf-16"?>
<movie>
<title><![CDATA[Monster House]]></title>
<plot><![CDATA[Monsters under the bed are scary enough, but what happens when an entire house is out to get you? Three teens aim to find out when they go up against a decrepit neighboring home and unlock its frightening secrets.]]></plot>
<tagline><![CDATA[The House is . . . ALIVE!]]></tagline>
<year>2006</year>
<id>tt0385880</id>
<rating>57</rating>
<votes>74</votes>
<budget>0</budget>
<revenue>0</revenue>
<company><![CDATA[Sony Pictures Entertainment]]></company>
<genre>
<name>
<string>Adventure</string>
<string>Animation</string>
<string>Comedy</string>
<string>Fantasy</string>
<string>Mystery</string>
<string>Science Fiction</string>
<string>Family</string>
</name>
</genre>
</movie>
但输出不符合预期,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<movie>
<title><![CDATA[Con Air]]></title>
<plot><![CDATA[When the government puts all its rotten criminal eggs in one airborne basket, it's asking for trouble. Before you can say, "Pass the barf bag," the crooks control the plane, led by creepy Cyrus "The Virus" Grissom. Watching his every move is the just-released Cameron Poe, who'd rather reunite with his family. The action climaxes with an incredible crash sequence in Las Vegas.]]></plot>
<tagline><![CDATA[They were deadly on the ground; Now they have wings]]></tagline>
<year>1997</year>
<id>tt0118880</id>
<rating>65</rating>
<votes>93</votes>
<budget>75000000</budget>
<revenue>224012234</revenue>
<company><![CDATA[Touchstone Pictures]]></company>
<genre>
<name><![CDATA[Action]]></name>
<name><![CDATA[Adventure]]></name>
<name><![CDATA[Thriller]]></name>
</genre>
</movie>
<?xml version="1.0" encoding="utf-16"?>
<movie>
<title><![CDATA[Monster House]]></title>
<plot><![CDATA[Monsters under the bed are scary enough, but what happens when an entire house is out to get you? Three teens aim to find out when they go up against a decrepit neighboring home and unlock its frightening secrets.]]></plot>
<tagline><![CDATA[The House is . . . ALIVE!]]></tagline>
<year>2006</year>
<id>tt0385880</id>
<rating>57</rating>
<votes>74</votes>
<budget>0</budget>
<revenue>0</revenue>
<company><![CDATA[Sony Pictures Entertainment]]></company>
<genre>
<name>
<string>Adventure</string>
<string>Animation</string>
<string>Comedy</string>
<string>Fantasy</string>
<string>Mystery</string>
<string>Science Fiction</string>
<string>Family</string>
</name>
</genre>
</movie>

2006
tt0385880
57
74
0
0
冒险
动画
喜剧片
幻想
神秘的
科幻小说
家庭

如何像第一个示例中的类型子节点那样创建子节点xml?

我认为应该通过使用适当的注释来解决元素名为“string”而不是“name”的问题,如中所述

您必须稍微修改一下您的类(我不确定您是否可以为名称获取CDATA,但应该可以):


您好,感谢您的响应,我还将字符串[]类型更改为XMLCDATA节[],以便在CDATA中输出XmlArrayItem,如第一个示例所示。下面是代码:您好,感谢您的响应,我还将字符串[]类型更改为XMLCDATA节[],以便在CDATA中输出XmlArrayItem,如第一个示例所示。
下面是代码:`public class Movie{..[XmlArray(“流派”)][XmlArrayItem(“名称”)]public XMLCDATA节[]流派{get;set;}`