Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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# XmlSerializerFormat不是嵌套的XML_C#_Xml Serialization - Fatal编程技术网

C# XmlSerializerFormat不是嵌套的XML

C# XmlSerializerFormat不是嵌套的XML,c#,xml-serialization,C#,Xml Serialization,对于我的项目,我使用XmlSerializerFormat进行序列化。我有一门课,例如: [SoapInclude(typeof(Thing))] [SoapType("Thing", "TheNs", IncludeInSchema = true)] public class Thing { [SoapElement(IsNullable = true, DataType = "string")] public string ThingName = "aap"; } [SoapType(

对于我的项目,我使用XmlSerializerFormat进行序列化。我有一门课,例如:

[SoapInclude(typeof(Thing))]
[SoapType("Thing", "TheNs", IncludeInSchema = true)]
public class Thing
{
 [SoapElement(IsNullable = true, DataType = "string")]
 public string ThingName = "aap";
}

[SoapType("Transportation", "TheNs", IncludeInSchema = true)]
[SoapInclude(typeof(Transportation))]
public class Transportation
{
 // The SoapElementAttribute specifies that the
 // generated XML element name will be "Wheels"
 // instead of "Vehicle".
 [SoapElement("Wheels")]
 public string Vehicle;
 [SoapElement(DataType = "dateTime")]
 public DateTime CreationDate;
 [SoapElement(IsNullable = true)]
 public Thing Thing;

} 
从此类生成的XML具有以下格式:

<wrapper>
  <q1:Transportation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" xmlns:q1="TheNs">
    <Truck xsi:type="xsd:string">MyCar</Truck>
    <CreationDate xsi:type="xsd:dateTime">2010-01-05T16:03:01.9436034+01:00</CreationDate>
    <Thing href="#id2" />
  </q1:Transportation>
  <q2:Thing id="id2" d2p1:type="q2:Thing" xmlns:d2p1="http://www.w3.org/2001/XMLSchema-instance" xmlns:q2="TheNs">
    <ThingName xmlns:q3="http://www.w3.org/2001/XMLSchema" d2p1:type="q3:string">thing</ThingName>
  </q2:Thing>
</wrapper>
<wrapper>
  <Transportation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Vehicle>MyCar</Vehicle>
    <CreationDate>2010-01-05T16:03:01.7562378+01:00</CreationDate>
    <Thing>
      <ThingName>thing</ThingName>
    </Thing>
  </Transportation>
</wrapper>
  <wrapper>
  <Transportation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <Vehicle>MyCar</Vehicle>
     <CreationDate>2010-01-05T16:03:01.7562378+01:00</CreationDate>
     <Thing>
         <ThingName>thing</ThingName>
     </Thing>
  </Transportation>
 </wrapper>
生成的XML如下所示

 <wrapper>
 <q1:Transportation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" xmlns:q1="TheNs">
 <Truck xsi:type="xsd:string">MyCar</Truck>
 <CreationDate xsi:type="xsd:dateTime">2010-01-05T16:03:01.9436034+01:00</CreationDate>
 <Thing href="#id2" />
  </q1:Transportation>
  <q2:Thing id="id2" d2p1:type="q2:Thing" xmlns:d2p1="http://www.w3.org/2001/XMLSchema-instance" xmlns:q2="TheNs">
  <ThingName xmlns:q3="http://www.w3.org/2001/XMLSchema" d2p1:type="q3:string">thing</ThingName>
  </q2:Thing>
  </wrapper>

我的车
2010-01-05T16:03:01.9436034+01:00
事情
我需要的XML应采用以下格式:

<wrapper>
  <q1:Transportation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" xmlns:q1="TheNs">
    <Truck xsi:type="xsd:string">MyCar</Truck>
    <CreationDate xsi:type="xsd:dateTime">2010-01-05T16:03:01.9436034+01:00</CreationDate>
    <Thing href="#id2" />
  </q1:Transportation>
  <q2:Thing id="id2" d2p1:type="q2:Thing" xmlns:d2p1="http://www.w3.org/2001/XMLSchema-instance" xmlns:q2="TheNs">
    <ThingName xmlns:q3="http://www.w3.org/2001/XMLSchema" d2p1:type="q3:string">thing</ThingName>
  </q2:Thing>
</wrapper>
<wrapper>
  <Transportation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Vehicle>MyCar</Vehicle>
    <CreationDate>2010-01-05T16:03:01.7562378+01:00</CreationDate>
    <Thing>
      <ThingName>thing</ThingName>
    </Thing>
  </Transportation>
</wrapper>
  <wrapper>
  <Transportation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <Vehicle>MyCar</Vehicle>
     <CreationDate>2010-01-05T16:03:01.7562378+01:00</CreationDate>
     <Thing>
         <ThingName>thing</ThingName>
     </Thing>
  </Transportation>
 </wrapper>

我的车
2010-01-05T16:03:01.7562378+01:00
事情

您无需添加答案即可提供更新。只需编辑问题并将更新添加到末尾。谢谢。您无需添加答案即可提供更新。只需编辑问题并将更新添加到末尾。谢谢