0

I am a c# developer with little experience with xml. Basically i need to create the below XML file from data i have from many sources.

<Manifests>
  <Manifest>
    <MawbNo num="016-22221414">
      <ArrivalDate>31/07/2016</ArrivalDate>
      <ArrivalTime>16:20:00</ArrivalTime>
      <HawbQty>3</HawbQty>
      <FlightNo>aw23</FlightNo>
      <AirlineCompany>1201</AirlineCompany>
      <CtryOfImport>5058</CtryOfImport>
      <PortOfLoading>USLAX</PortOfLoading>
      <AirTerminal>6981</AirTerminal>
      <AgentID>3243</AgentID>
      <Hawb>
        <Consignee>
          <CustomerID>35427891</CustomerID>
          <Customerreference />
          <DocumentCtry />
          <CompanyId>35427891</CompanyId>
          <Name>Robert Mauli</Name>
          <Addr1>E22 </Addr1>
          <Addr2>New York</Addr2>
          <Addr3>Apt 5</Addr3>
          <Addr4>01284328339IL</Addr4>
          <PostZipCode>6688410</PostZipCode>
          <Telephone>9755-1234567</Telephone>
          <Cellular>331-3344333</Cellular>
          <Email>rob@gmail.com</Email>
        </Consignee>
        <Supplier>
          <ID />
          <Name>eBay</Name>
          <Addr1>325 9th Ave N</Addr1>
          <Addr2>Seattle, WA</Addr2>
          <Addr3>98109</Addr3>
          <Addr4>12</Addr4>
          <SupplierCtry>US</SupplierCtry>
        </Supplier>
        <GoodsTotal>
          <Value>59.99</Value>
          <Currency>USD</Currency>
          <Incoterms>DDP</Incoterms>
        </GoodsTotal>
        <Freight>
          <Value />
          <Currency />
        </Freight>
        <HawbNo num="GSH0000123" />
        <Individual>N</Individual>
        <CreateDate />
        <Status>1</Status>
        <Customs_Submition />
        <Work_Station>2</Work_Station>
        <Remarks />
        <Availability />
        <CustomsAgent />
        <Pieces>1</Pieces>
        <Weight>1.5</Weight>
        <Volume />
        <PackageType />
        <Description>Clothing</Description>
        <Attachments>
          <Attachment>
            <Type />
            <FileExtension />
            <Content />
          </Attachment>
        </Attachments>
      </Hawb>
      <Hawb>
        <Consignee>
          <CustomerID>123456789</CustomerID>
          <Customerreference />
          <DocumentCtry />
          <CompanyId>123456789</CompanyId>
          <Name>Yossi Levi</Name>
          <Addr1>Hadas 1</Addr1>
          <Addr2>Yavne</Addr2>
          <Addr3 />
          <Addr4>01288748339IL</Addr4>
          <PostZipCode>5454541</PostZipCode>
          <Telephone>050-7894561</Telephone>
          <Cellular>03-9876541</Cellular>
          <Email>barbara.rich@Gmail.com</Email>
        </Consignee>
        <Supplier>
          <ID />
          <Name>Amazon</Name>
          <Addr1>325 9th Ave N</Addr1>
          <Addr2>Seattle, WA</Addr2>
          <Addr3>98109</Addr3>
          <Addr4>14</Addr4>
          <SupplierCtry>US</SupplierCtry>
        </Supplier>
        <GoodsTotal>
          <Value>120.5</Value>
          <Currency>USD</Currency>
          <Incoterms>DDP</Incoterms>
        </GoodsTotal>
        <Freight>
          <Value />
          <Currency />
        </Freight>
        <HawbNo num="GSH0000454" />
        <Individual>N</Individual>
        <CreateDate />
        <Status>1</Status>
        <Customs_Submition />
        <Work_Station>2</Work_Station>
        <Remarks />
        <Availability />
        <CustomsAgent />
        <Pieces>1</Pieces>
        <Weight>4.5</Weight>
        <Volume />
        <PackageType />
        <Description>Computer Equipment</Description>
        <Attachments>
          <Attachment>
            <Type />
            <FileExtension />
            <Content />
          </Attachment>
        </Attachments>
      </Hawb>
      <Hawb>
        <Consignee>
          <CustomerID>987654321</CustomerID>
          <Customerreference />
          <DocumentCtry />
          <CompanyId>987654321</CompanyId>
          <Name>Dani Roter</Name>
          <Addr1>Raz 4</Addr1>
          <Addr2>broklyin</Addr2>
          <Addr3 />
          <Addr4>01288585339IL</Addr4>
          <PostZipCode>1234567</PostZipCode>
          <Telephone>334-9876541</Telephone>
          <Cellular>03-32423</Cellular>
          <Email>Chase.Roten@hotmail.com</Email>
        </Consignee>
        <Supplier>
          <ID />
          <Name>6pm</Name>
          <Addr1>325 9th Ave N</Addr1>
          <Addr2>Seattle, WA</Addr2>
          <Addr3>98109</Addr3>
          <Addr4>12</Addr4>
          <SupplierCtry>US</SupplierCtry>
        </Supplier>
        <GoodsTotal>
          <Value>404.99</Value>
          <Currency>USD</Currency>
          <Incoterms>DDP</Incoterms>
        </GoodsTotal>
        <Freight>
          <Value />
          <Currency />
        </Freight>
        <HawbNo num="GSH0000765" />
        <Individual>N</Individual>
        <CreateDate />
        <Status>1</Status>
        <Customs_Submition />
        <Work_Station>2</Work_Station>
        <Remarks />
        <Availability />
        <CustomsAgent />
        <Pieces>1</Pieces>
        <Weight>2</Weight>
        <Volume />
        <PackageType />
        <Description>Shoes</Description>
        <Attachments>
          <Attachment>
            <Type />
            <FileExtension />
            <Content />
          </Attachment>
        </Attachments>
      </Hawb>
    </MawbNo>
  </Manifest>
</Manifests>

What is the best way to do it? Should i create an class that have instances of the nested classes and XmlSerializer to turn the object? OR should i use xmlWriter and create each element?

Bottom line is that i need a simple method that get the properties fill them And create this complex XML file and im not sure on which approach i should Take?

Igor
  • 60,821
  • 10
  • 100
  • 175
itsikha
  • 82
  • 11
  • 1
    [Check this out](http://stackoverflow.com/questions/3187444/convert-xml-string-to-object) – Michael Oct 19 '16 at 14:39
  • How do you get that "data i receive from my database." ? If that's with EF classes you can serialize them. – H H Oct 19 '16 at 14:40
  • Actually some of the data come from database some from API and some are just const data ,And no im not using EF. – itsikha Oct 19 '16 at 14:53
  • 3
    There are a number of way to write xml data 1) Save from DataSet/DataTable. 2) Save from classes 3) Write directly to file. There is no prefer way. it depends on the amount of data you are writing to xml, how the data repeats, and how the data is grouped in existing code which method is best. – jdweng Oct 19 '16 at 14:57
  • 2
    `... Basically i need to create the below XML file from data i have from many sources...` <= Your title reads `Parsing a ...`. Parsing is the act of constructing a type/object from a string. You want to create a string (xml) from an object so Parsing is not the correct term. I updated the title of your question so it reflects what you want, feel free to tweak it further. – Igor Oct 19 '16 at 15:01
  • Well i decided to use the xmlseralization class. – itsikha Oct 19 '16 at 16:21

0 Answers0