先说下这个的背景吧,前些日子,有个以前的小同事说刚接触webservice,想解析下xml,记得我学的时候还是dom4j,sax的解析方式,最近看别人的代码用的jaxb的方式,觉得注解起来很简练,所以就拿jaxb试着写了一个,并一起总结一下,当做备忘录吧。
先看下xml的格式吧,如下
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <mo version="1.0.0"> <head> <businessType>PLANING_RECEIPTS</businessType> </head> <body> <planingReceiptsInfo> <manSign> <companyCode>发送方海关十位数编码</companyCode> <businessNo>业务编码</businessNo> <businessType>业务类型</businessType> <declareType>申报类型</declareType> <note>备注</note> </manSign> <manPlaningReceipts> <planingReceiptsId>计划入库单编号</planingReceiptsId> <manualId>账册编号</manualId> <customsCode>关区代码</customsCode> <companyCode>企业海关十位编码</companyCode> <companyName>企业名称</companyName> <grossWeight>毛重</grossWeight> <netWeight>净重</netWeight> <amount>件数</amount> <wrapType>包装种类</wrapType> <port>申报关区</port> <providerCodep>厂商编码</providerCodep> <type>业务类别</type> </manPlaningReceipts> <manPlaningReceiptsDetailList> <manPlaningReceiptsDetail> <planingReceiptsId>6</planingReceiptsId> <sourceNo>8</sourceNo> <itemNo>4</itemNo> <itemType>5</itemType> <goodsNo>3</goodsNo> <declareAmount>2</declareAmount> <totalPrice>9</totalPrice> <price>7</price> <countryCode>1</countryCode> </manPlaningReceiptsDetail> <manPlaningReceiptsDetail> <planingReceiptsId>6</planingReceiptsId> <sourceNo>8</sourceNo> <itemNo>4</itemNo> <itemType>5</itemType> <goodsNo>3</goodsNo> <declareAmount>2</declareAmount> <totalPrice>9</totalPrice> <price>7</price> <countryCode>1</countryCode> </manPlaningReceiptsDetail> </manPlaningReceiptsDetailList> </planingReceiptsInfo> </body> </mo>