<?xml version="1.0" encoding="utf-8"?>
<Root>
<Header>
<MessageReferenceNumber>I9DeoogUJg8ZBfA</MessageReferenceNumber>
<DocumentName>无车承运人电子路单</DocumentName>
<DocumentVersionNumber>2015WCCYR</DocumentVersionNumber>
<SenderCode>9285</SenderCode>
<RecipientCode>9396</RecipientCode>
<MessageSendingDateTime>9396</MessageSendingDateTime>
<MessageFunctionCode>9</MessageFunctionCode>
</Header>
<Body>
<OriginalDocumentNumber>31314534223</OriginalDocumentNumber>
<ShippingNoteNumber>532135</ShippingNoteNumber>
<Carrier>浙江未名物流有限公司</Carrier>
<UnifiedSocialCreditIdentifier>11991000010647510A</UnifiedSocialCreditIdentifier>
<PermitNumber>310112002939</PermitNumber>
<ConsignmentDateTime>20161229145036</ConsignmentDateTime>
<BusinessTypeCode>1002996</BusinessTypeCode>
<DespatchActualDateTime>20161229165036</DespatchActualDateTime>
<GoodsReceiptDateTime>20161231165036</GoodsReceiptDateTime>
<ConsignorInfo>
<Consignor>浙江新华书店</Consignor>
<PersonalIdentityDocument>330102198402124417</PersonalIdentityDocument>
<PlaceOfLoading>浙江省杭州市江干区</PlaceOfLoading>
<CountrySubdivisionCode>330104</CountrySubdivisionCode>
</ConsignorInfo>
<ConsigneeInfo>
<Consignee>台州新华书店</Consignee>
<GoodsReceiptPlace>浙江省台州市椒江区</GoodsReceiptPlace>
<CountrySubdivisionCode>331002</CountrySubdivisionCode>
</ConsigneeInfo>
<PriceInfo>
<TotalMonetaryAmount>430.012</TotalMonetaryAmount>
<Remark>人民币</Remark>
</PriceInfo>
<VehicleInfo>
<LicensePlateTypeCode>01</LicensePlateTypeCode>
<VehicleNumber>浙A32153</VehicleNumber>
<VehicleClassificationCode>H01</VehicleClassificationCode>
<VehicleTonnage>20.00</VehicleTonnage>
<RoadTransportCertificateNumber>330111003790</RoadTransportCertificateNumber>
<TrailerVehiclePlateNumber>浙RR527挂</TrailerVehiclePlateNumber>
<Owner>温州市侯海货运有限公司</Owner>
<PermitNumber>330301000307</PermitNumber>
<Driver>
<NameOfPerson>张三</NameOfPerson>
<QualificationCertificateNumber>431224198708273098</QualificationCertificateNumber>
<TelephoneNumber>15167338765</TelephoneNumber>
</Driver>
<GoodsInfo>
<DescriptionOfGoods>教科书</DescriptionOfGoods>
<CargoTypeClassificationCode>999</CargoTypeClassificationCode>
<GoodsItemGrossWeight>151.333</GoodsItemGrossWeight>
<Cube>11.3333</Cube>
<TotalNumberOfPackages>12</TotalNumberOfPackages>
</GoodsInfo>
</VehicleInfo>
<FreeText>文本</FreeText>
</Body>
</Root>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace test_jiekou.models
{
public class GeneraterXML
{
public Root GetRoot() {
ConsignorInfo consignorinfo = new ConsignorInfo();
consignorinfo.Consignor = "浙江新华书店";
consignorinfo.PersonalIdentityDocument = "330102198402124417";
consignorinfo.PlaceOfLoading = "浙江省杭州市江干区";
consignorinfo.CountrySubdivisionCode = "330104";
ConsigneeInfo consigneeinfo = new ConsigneeInfo();
consigneeinfo.Consignee = "台州新华书店";
consigneeinfo.GoodsReceiptPlace = "浙江省台州市椒江区";
consigneeinfo.CountrySubdivisionCode = "331002";
PriceInfo priceinfo = new PriceInfo();
priceinfo.TotalMonetaryAmount = "430.012";
priceinfo.Remark = "人民币";
Driver driver = new Driver();
driver.NameOfPerson = "张三";
driver.QualificationCertificateNumber = "431224198708273098";
driver.TelephoneNumber = "15167338765";
GoodsInfo goodsinfo = new GoodsInfo();
goodsinfo.DescriptionOfGoods = "教科书";
goodsinfo.CargoTypeClassificationCode = "999";
goodsinfo.GoodsItemGrossWeight = "151.333";
goodsinfo.Cube = "11.3333";
goodsinfo.TotalNumberOfPackagese = "12";
VehicleInfo vehicleinfo = new VehicleInfo();
vehicleinfo.LicensePlateTypeCode = "01";
vehicleinfo.VehicleNumber = "浙A32153";
vehicleinfo.VehicleClassificationCode = "H01";
vehicleinfo.VehicleTonnage = "20.00";
vehicleinfo.RoadTransportCertificateNumber = "330111003790";
vehicleinfo.TrailerVehiclePlateNumber = "浙RR527挂";
vehicleinfo.Owner = "温州市侯海货运有限公司";
vehicleinfo.PermitNumber = "330301000307";
Driver[] arraydriver = new Driver[1];
arraydriver[0] = driver;
vehicleinfo.driver = arraydriver;
GoodsInfo[] arraygoodsinfo = new GoodsInfo[1];
arraygoodsinfo[0] = goodsinfo;
vehicleinfo.goodsinfo = arraygoodsinfo;
Body body = new Body();
body.OriginalDocumentNumber = "31314534223";
body.ShippingNoteNumber = "532135";
body.Carrier = "浙江未名物流有限公司";
body.UnifiedSocialCreditIdentifier = "11991000010647510A";
body.PermitNumber = "310112002939";
body.ConsignmentDateTime = "20161229145036";
body.BusinessTypeCode = "1002996";
body.DespatchActualDateTime = "20161229165036";
body.GoodsReceiptDateTime = "20161231165036";
body.consigneeinfo = consigneeinfo;
body.consignorinfo = consignorinfo;
body.priceinfo = priceinfo;
VehicleInfo[] arrayvehicleinfo = new VehicleInfo[1];
arrayvehicleinfo[0] = vehicleinfo;
body.vehicleinfo = arrayvehicleinfo;
body.FreeText = "文本";
Header header = new Header();
header.MessageReferenceNumber = "I9DeoogUJg8ZBfA";
header.DocumentName = "无车承运人电子路单";
header.DocumentVersionNumber = "2015WCCYR";
header.SenderCod = "9285";
header.RecipientCode = "9396";
header.MessageSendingDateTime = "9396";
header.MessageFunctionCode = "9";
Root root = new Root();
root.header = header;
root.body = body;
return root;
}
public string zhuanXML() {
Root Md_Root = GetRoot();
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration declaration= xmlDoc.CreateXmlDeclaration("1.0","utf-8",null);
xmlDoc.AppendChild(declaration);
XmlNode XRoot = xmlDoc.CreateElement("Root");
XmlNode XHeader = xmlDoc.CreateElement("Header");
XmlNode XBody = xmlDoc.CreateElement("Body");
Header header = Md_Root.header;
XmlNode MessageReferenceNumber = xmlDoc.CreateElement("MessageReferenceNumber");
XmlNode DocumentName = xmlDoc.CreateElement("DocumentName");
XmlNode DocumentVersionNumber = xmlDoc.CreateElement("DocumentVersionNumber");
XmlNode SenderCode = xmlDoc.CreateElement("SenderCode");
XmlNode RecipientCode = xmlDoc.CreateElement("RecipientCode");
XmlNode MessageSendingDateTime = xmlDoc.CreateElement("MessageSendingDateTime");
XmlNode MessageFunctionCode = xmlDoc.CreateElement("MessageFunctionCode");
MessageReferenceNumber.InnerText = header.MessageReferenceNumber;
DocumentName.InnerText = header.DocumentName;
DocumentVersionNumber.InnerText = header.DocumentVersionNumber;
SenderCode.InnerText = header.SenderCod;
RecipientCode.InnerText = header.RecipientCode;
MessageSendingDateTime.InnerText = header.MessageSendingDateTime;
MessageFunctionCode.InnerText = header.MessageFunctionCode;
XHeader.AppendChild(MessageReferenceNumber);
XHeader.AppendChild(DocumentName);
XHeader.AppendChild(DocumentVersionNumber);
XHeader.AppendChild(SenderCode);
XHeader.AppendChild(RecipientCode);
XHeader.AppendChild(MessageSendingDateTime);
XHeader.AppendChild(MessageFunctionCode);
Body body = Md_Root.body;
XmlNode OriginalDocumentNumber = xmlDoc.CreateElement("OriginalDocumentNumber");
XmlNode ShippingNoteNumber = xmlDoc.CreateElement("ShippingNoteNumber");
XmlNode Carrier = xmlDoc.CreateElement("Carrier");
XmlNode UnifiedSocialCreditIdentifier = xmlDoc.CreateElement("UnifiedSocialCreditIdentifier");
XmlNode PermitNumber = xmlDoc.CreateElement("PermitNumber");
XmlNode ConsignmentDateTime = xmlDoc.CreateElement("ConsignmentDateTime");
XmlNode BusinessTypeCode = xmlDoc.CreateElement("BusinessTypeCode");
XmlNode DespatchActualDateTime = xmlDoc.CreateElement("DespatchActualDateTime");
XmlNode GoodsReceiptDateTime = xmlDoc.CreateElement("GoodsReceiptDateTime");
OriginalDocumentNumber.InnerText = body.OriginalDocumentNumber;
ShippingNoteNumber.InnerText = body.ShippingNoteNumber;
Carrier.InnerText = body.Carrier;
UnifiedSocialCreditIdentifier.InnerText = body.UnifiedSocialCreditIdentifier;
PermitNumber.InnerText = body.PermitNumber;
ConsignmentDateTime.InnerText = body.ConsignmentDateTime;
BusinessTypeCode.InnerText = body.BusinessTypeCode;
DespatchActualDateTime.InnerText = body.DespatchActualDateTime;
GoodsReceiptDateTime.InnerText = body.GoodsReceiptDateTime;
XBody.AppendChild(OriginalDocumentNumber);
XBody.AppendChild(ShippingNoteNumber);
XBody.AppendChild(Carrier);
XBody.AppendChild(UnifiedSocialCreditIdentifier);
XBody.AppendChild(PermitNumber);
XBody.AppendChild(ConsignmentDateTime);
XBody.AppendChild(BusinessTypeCode);
XBody.AppendChild(DespatchActualDateTime);
XBody.AppendChild(GoodsReceiptDateTime);
ConsignorInfo consignorinfo = body.consignorinfo;
XmlNode Xconsignorinfo = xmlDoc.CreateElement("ConsignorInfo");
XmlNode Consignor = xmlDoc.CreateElement("Consignor");
XmlNode PersonalIdentityDocument = xmlDoc.CreateElement("PersonalIdentityDocument");
XmlNode PlaceOfLoading = xmlDoc.CreateElement("PlaceOfLoading");
XmlNode CountrySubdivisionCode = xmlDoc.CreateElement("CountrySubdivisionCode");
Consignor.InnerText = consignorinfo.Consignor;
PersonalIdentityDocument.InnerText = consignorinfo.PersonalIdentityDocument;
PlaceOfLoading.InnerText = consignorinfo.PlaceOfLoading;
CountrySubdivisionCode.InnerText = consignorinfo.CountrySubdivisionCode;
Xconsignorinfo.AppendChild(Consignor);
Xconsignorinfo.AppendChild(PersonalIdentityDocument);
Xconsignorinfo.AppendChild(PlaceOfLoading);
Xconsignorinfo.AppendChild(CountrySubdivisionCode);
XBody.AppendChild(Xconsignorinfo);
ConsigneeInfo consigneeinfo = body.consigneeinfo;
XmlNode Xconsigneeinfo = xmlDoc.CreateElement("ConsigneeInfo");
XmlNode Consignee = xmlDoc.CreateElement("Consignee");
XmlNode GoodsReceiptPlace = xmlDoc.CreateElement("GoodsReceiptPlace");
XmlNode CountrySubdivisionCode2 = xmlDoc.CreateElement("CountrySubdivisionCode");
Consignee.InnerText = consigneeinfo.Consignee;
GoodsReceiptPlace.InnerText = consigneeinfo.GoodsReceiptPlace;
CountrySubdivisionCode2.InnerText = consigneeinfo.CountrySubdivisionCode;
Xconsigneeinfo.AppendChild(Consignee);
Xconsigneeinfo.AppendChild(GoodsReceiptPlace);
Xconsigneeinfo.AppendChild(CountrySubdivisionCode2);
XBody.AppendChild(Xconsigneeinfo);
PriceInfo priceinfo = body.priceinfo;
XmlNode XPriceInfo = xmlDoc.CreateElement("PriceInfo");
XmlNode TotalMonetaryAmount = xmlDoc.CreateElement("TotalMonetaryAmount");
XmlNode Remark = xmlDoc.CreateElement("Remark");
TotalMonetaryAmount.InnerText = priceinfo.TotalMonetaryAmount;
Remark.InnerText = priceinfo.Remark;
XPriceInfo.AppendChild(TotalMonetaryAmount);
XPriceInfo.AppendChild(Remark);
XBody.AppendChild(XPriceInfo);
foreach (VehicleInfo vehicleinfo in body.vehicleinfo)
{
XmlNode XVehicleInfo = xmlDoc.CreateElement("VehicleInfo");
XmlNode LicensePlateTypeCode = xmlDoc.CreateElement("LicensePlateTypeCode");
XmlNode VehicleNumber = xmlDoc.CreateElement("VehicleNumber");
XmlNode VehicleClassificationCode = xmlDoc.CreateElement("VehicleClassificationCode");
XmlNode VehicleTonnage = xmlDoc.CreateElement("VehicleTonnage");
XmlNode RoadTransportCertificateNumber = xmlDoc.CreateElement("RoadTransportCertificateNumber");
XmlNode TrailerVehiclePlateNumber = xmlDoc.CreateElement("TrailerVehiclePlateNumber");
XmlNode Owner = xmlDoc.CreateElement("Owner");
XmlNode VPermitNumber = xmlDoc.CreateElement("PermitNumber");
LicensePlateTypeCode.InnerText = vehicleinfo.LicensePlateTypeCode;
VehicleNumber.InnerText = vehicleinfo.VehicleNumber;
VehicleClassificationCode.InnerText = vehicleinfo.VehicleClassificationCode;
VehicleTonnage.InnerText = vehicleinfo.VehicleTonnage;
RoadTransportCertificateNumber.InnerText = vehicleinfo.RoadTransportCertificateNumber;
TrailerVehiclePlateNumber.InnerText = vehicleinfo.TrailerVehiclePlateNumber;
Owner.InnerText = vehicleinfo.Owner;
VPermitNumber.InnerText = vehicleinfo.PermitNumber;
XVehicleInfo.AppendChild(LicensePlateTypeCode);
XVehicleInfo.AppendChild(VehicleNumber);
XVehicleInfo.AppendChild(VehicleClassificationCode);
XVehicleInfo.AppendChild(VehicleTonnage);
XVehicleInfo.AppendChild(RoadTransportCertificateNumber);
XVehicleInfo.AppendChild(TrailerVehiclePlateNumber);
XVehicleInfo.AppendChild(Owner);
XVehicleInfo.AppendChild(Owner);
XVehicleInfo.AppendChild(VPermitNumber);
foreach (Driver driver in vehicleinfo.driver)
{
XmlNode Xdriver = xmlDoc.CreateElement("Driver");
XmlNode NameOfPerson = xmlDoc.CreateElement("NameOfPerson");
XmlNode QualificationCertificateNumber = xmlDoc.CreateElement("QualificationCertificateNumber");
XmlNode TelephoneNumber = xmlDoc.CreateElement("TelephoneNumber");
NameOfPerson.InnerText = driver.NameOfPerson;
QualificationCertificateNumber.InnerText = driver.QualificationCertificateNumber;
TelephoneNumber.InnerText = driver.TelephoneNumber;
Xdriver.AppendChild(NameOfPerson);
Xdriver.AppendChild(QualificationCertificateNumber);
Xdriver.AppendChild(TelephoneNumber);
XVehicleInfo.AppendChild(Xdriver);
}
foreach (GoodsInfo goodsinfo in vehicleinfo.goodsinfo)
{
XmlNode Xgoodsinfo = xmlDoc.CreateElement("GoodsInfo");
XmlNode DescriptionOfGoods = xmlDoc.CreateElement("DescriptionOfGoods");
XmlNode CargoTypeClassificationCode = xmlDoc.CreateElement("CargoTypeClassificationCode");
XmlNode GoodsItemGrossWeight = xmlDoc.CreateElement("GoodsItemGrossWeight");
XmlNode Cube = xmlDoc.CreateElement("Cube");
XmlNode TotalNumberOfPackages = xmlDoc.CreateElement("TotalNumberOfPackages");
DescriptionOfGoods.InnerText = goodsinfo.DescriptionOfGoods;
CargoTypeClassificationCode.InnerText = goodsinfo.CargoTypeClassificationCode;
GoodsItemGrossWeight.InnerText = goodsinfo.GoodsItemGrossWeight;
Cube.InnerText = goodsinfo.Cube;
TotalNumberOfPackages.InnerText = goodsinfo.TotalNumberOfPackagese;
Xgoodsinfo.AppendChild(DescriptionOfGoods);
Xgoodsinfo.AppendChild(CargoTypeClassificationCode);
Xgoodsinfo.AppendChild(GoodsItemGrossWeight);
Xgoodsinfo.AppendChild(Cube);
Xgoodsinfo.AppendChild(TotalNumberOfPackages);
XVehicleInfo.AppendChild(Xgoodsinfo);
}
XBody.AppendChild(XVehicleInfo);
}
XmlNode Xfreetext = xmlDoc.CreateElement("FreeText");
Xfreetext.InnerText = body.FreeText;
XBody.AppendChild(Xfreetext);
XRoot.AppendChild(XHeader);
XRoot.AppendChild(XBody);
xmlDoc.AppendChild(XRoot);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
xmlDoc.Save(ms);
System.IO.StreamReader sr = new System.IO.StreamReader(ms, System.Text.Encoding.UTF8);
ms.Position = 0;
string xmlString = sr.ReadToEnd();
return xmlString;
}
}
}