创建XML文档片段

时间:2016-10-19 14:36:06

标签: c# .net xml

我是一名c#开发人员,对xml缺乏经验。 基本上我需要从许多来源的数据创建以下XML文件。

<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>

最好的方法是什么? 我应该创建一个具有嵌套类和XmlSerializer实例的类来转动对象吗?或者我应该使用xmlWriter并创建每个元素吗?

底线是我需要一个简单的方法来获取属性填充它们并创建这个复杂的XML文件,我不知道我应该采取哪种方法?

0 个答案:

没有答案