1

データを送信するときに一致させる必要がある XML ファイルがあります。私が何をしても、プライマリ配列の余分なラッパーになってしまいます。XML は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<contracts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <contract>
        <productType>VSC</productType>
        <contractNumber>ABS1869169</contractNumber>
        <vehicle>
            <vin>JTKDE177160100198</vin>
            <odometer>128135</odometer>
            <purchasePrice>5574</purchasePrice>
      </vehicle>
    </contract>
    <contract>
        <productType>VSC</productType>
        <contractNumber>ABS1865421</contractNumber>
        <vehicle>
            <vin>LTGSE177160154878</vin>
            <odometer>119154</odometer>
            <purchasePrice>6509</purchasePrice>
        </vehicle>
    </contract>
</contracts>

私はこのような余分な契約で終わります:

<?xml version="1.0" encoding="utf-8"?>
<contracts xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <contracts>
    <contract>
      <productType>VSC</productType>
      <contractNumber>ABS1869169</contractNumber>
      <vehicle>
        <vin>JTKDE177160100198</vin>
        <odometer>128135</odometer>
        <purchasePrice>5574</purchasePrice>
      </vehicle>
    </contract>
    <contract>
      <productType>VSC</productType>
      <contractNumber>ABS1865421</contractNumber>
      <vehicle>
        <vin>LTGSE177160154878</vin>
        <odometer>119154</odometer>
        <purchasePrice>6509</purchasePrice>
      </vehicle>
    </contract>
  </contracts>
</contracts>

これが私が持っているコードです。

Public Class contracts

    Public contracts() As contract

End Class


Public Class contract
    Public productType As String = "VSC"
    Public contractNumber As String
    Public vehicle As New contractVehicle
End Class

Public Class contractVehicle
    Public vin As String
    Public odometer As String
    Public purchasePrice As String
End Class


    Dim serializer As New XmlSerializer(GetType(contracts))
    Using stream As Stream = New FileStream("C:\Code\TestXML2.xml", FileMode.Create)
        Dim s As New XmlWriterSettings()
        s.Indent = True
        s.Encoding = Encoding.UTF8
        Dim writer As XmlWriter = XmlTextWriter.Create(stream, s)
        serializer.Serialize(writer, vx)
        writer.Close()
    End Using
4

1 に答える 1