0

I am generating an XML file that I am sending to another system. The XML file generates correctly however the secondary system requires specific headers to deserialize correctly.

I am struggling with the XML tags and how to structure my classes that insert the data.

PostShipmentNotesBD -> ShipmentNoteBD -> Shipmentheader -> ShipmentDetailsBD -> MerchandiseLineBD
[XmlType("PostShipmentNotes")] -> [XmlType("ShipmentNote")] -> [XmlType("ShipmentHeader")] -> [XmlType("ShipmentDetails")] -> [XmlType("MerchandiseLine")]

For whatever reason the PostShipmentNotes and MerchandiseLines use the XMLType as the header but the rest do not? I have played around with roots, elements and more but I am a bit out of my area of knowledge and just looking for the right direction.

<?xml version="1.0" encoding="utf-8"?>
<PostShipmentNotes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <ShipmentNoteBD>
    <ShipmentHeader>
      <CustomerName>Some Company</CustomerName>
      <ShipmentStatusPrinted>Y</ShipmentStatusPrinted>
      <ShipCode>1010</ShipCode>
      <PlannedShipmentDate>2021-11-10</PlannedShipmentDate>
      <SalesOrder>666777</SalesOrder>
      <ShipAddress1>Big Long Street Name</ShipAddress1>
      <ShipAddress2> </ShipAddress2>
    </ShipmentHeader>
    <ShipmentDetailsBD>
      <MerchandiseLine>
        <SalesOrderLine>1</SalesOrderLine>
        <ShipmentQty>21</ShipmentQty>
        <OverOrUnderShipment>N</OverOrUnderShipment>
      </MerchandiseLine>
    </ShipmentDetailsBD>
  </ShipmentNoteBD>
</PostShipmentNotes>
mcr.netcore
  • 55
  • 1
  • 7
  • 2
    The following may be helpful: https://stackoverflow.com/questions/68605811/xmlserializer-find-element-with-name-and-attribute-value/68607179#68607179 and https://stackoverflow.com/questions/68875589/unable-to-parse-xml-attribute-value-into-c-sharp-enum-in-a-desired-way/68877099#68877099 . Alternatively, you can also add a new class. Then copy your XML (ex: ctrl-C), In VS menu, click: Edit => Paste Special => Paste XML As Classes. – Tu deschizi eu inchid Nov 07 '21 at 23:31
  • Cheers the second link helped me figure it out. My nested classes could be defined as XmlElement within the parent class rather than trying to define the XmlType – mcr.netcore Nov 08 '21 at 01:01
  • Header are not XML, they are HTML headers that is used as part of the HTML Request/Response. If you are using SML Serialization the headers may be attributes that you are adding to the c# classes. – jdweng Nov 08 '21 at 12:32

0 Answers0