Background系统

一、背景

在许多开发需求中都解析xml文件的需求,对于规格复杂的xml文件,方法很多主要有JDK原生dom形式,SAX形式,DOM4J ,JAXB 4种方式,但是JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术。因此本文主要介绍运用Springboot系统结合 JAXB技术,制作定时任务解析指定文件夹内的xml文件并且保存相应的操作记录到数据库当中。可以更好的优化和解决解析规格复杂xml的问题。

二、Background系统介绍

(一)结构介绍

Background是一个SpringBoot项目主要是由服务实现层的service,SechduleService和各个由xml各个节点对应的实体类Bean构成。

(二)功能介绍

1、JAXB

全称是Java Architecture for XML Binding简称JAXB允许Java开发人员将Java类映射为XML表示方式。JAXB提供两种主要特性:将一个Java对象序列化为XML,以及反向操作,将XML解析成Java对象。换句话说,JAXB允许以XML格式存储和读取数据,而不需要程序的类结构实现特定的读取XML和保存XML的代码。
当规格复杂且经常变化时JAXB特别有用。JAXB官网 API链接 文档

2、Background

其核心定时读取指定目录文件,读取里面数据,将成功的文件移动到指定文件夹,记录操作记录到数据库。
其流程图如下所示

三、例子

运用jaxb技术可以很好实现java对象和xml的转换,首先我们约定好规则:
定时读取指定文件夹 的内容,然后成功读取则把文件重新命名移动到成功文件夹,失败则直接移动到失败的文件夹
规则配置如下
#incoming shipment
cnshipment.pollingTime=0/10 * * * * ?
shipment.path.in=file:C:/FMS/background/polosap/incoming/cnShipment
shipment.path.success=file:C:/FMS/background/polosap/incoming/completed/cnShipment
shipment.path.fail=file:C:/FMS/background/polosap/incoming/failed/cnShipment

比如我们要解析BlueWave_20190727101739.xml文件

1.1 首先:运用JAXB技术创建出和xml文件对应的PO文件,运用jaxb的注解对应到xml文件的根元素;

简单说明一下jaxb常用的注解如下
@XmlRootElement(name = “Country”)
将Java类或枚举类型映射成XML中根元素,设置name属性的值可指定义根元素名称,不设置则默认为类型首字母小写的名称。
@XmlType(propOrder = {“name”, “capital”, “population”, “foundationTime”})
将Java类后枚举类型映射到XML模式类型,设置propOrder可以指定生成XML中各元素的先后顺序。
@XmlElement(name = “CFoundationTime”)
将JavaBean中的字段值映射到XML元素,设置name属性的值可指定XML元素的名称。
@XmlAttribute(name = “CRank”, required = false)
将JavaBean中的字段映射到XML中元素的属性,设置name属性的值可指定xml中元素属性的名称;
至于required属性,官方文档是说指定 XML 模式属性是可选的还是必需的,不是特别理解。
@XmlElementWrapper(name = “CountryWrapper”)
为集合生成xml包装器元素,简单来讲就是使XML元素更有层次感,更美观,该注解只能用在集合上。

因此此创建的java文件和xml文件对应根元素如下图所示:
主要jaxb的po对应xml原理相近因此主要展示前面两个PO,主要了解其中创建PO的规律
比如Shipments.java文件和xml对应如下

Shipment.java和xml文件对应如下

1.2 然后 运用到的是Spring注解,首先通过运用@Service创建的服务层组件,创建ShipmentMonitorService.java文件。主要代码如下

package com.ontop.job.geodis.monitor;import java.io.File;
import java.io.FileInputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;import javax.transaction.Transactional;import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;import com.ontop.job.geodis.common.ResourceService;
import com.ontop.job.geodis.common.Utils;
import com.ontop.job.geodis.dao.CartonDao;
import com.ontop.job.geodis.dao.OrderDao;
import com.ontop.job.geodis.dao.ShipmentDao;
import com.ontop.job.geodis.entity.shipment.CartonPO;
import com.ontop.job.geodis.entity.shipment.OrderPO;
import com.ontop.job.geodis.entity.shipment.ShipmentPO;
import com.ontop.job.geodis.mapping.shipment.CartonType;
import com.ontop.job.geodis.mapping.shipment.OrderType;
import com.ontop.job.geodis.mapping.shipment.ShipmentType;
import com.ontop.job.geodis.mapping.shipment.Shipments;
import com.ontop.job.geodis.service.ProcessLogService;@Service
public class ShipmentMonitorService {private static final Logger logger = LoggerFactory.getLogger(ShipmentMonitorService.class);@Value("${shipment.path.in}")private String in;@Value("${shipment.path.success}")private String success;@Value("${shipment.path.fail}")private String fail;@Autowiredprivate ResourceService resourceService;@Autowiredprivate ShipmentDao shipmentDao;@Autowiredprivate OrderDao orderDao;@Autowiredprivate CartonDao cartonDao;@Autowiredprivate ProcessLogService logService;@Scheduled(cron = "${cnshipment.pollingTime}")public void checkInputFile() {File inFolder = resourceService.getFile(in);if (inFolder == null || !inFolder.isDirectory()) {return;}File[] fileList = inFolder.listFiles();for (int i = 0; i < fileList.length; i++) {File xmlFile = fileList[i];if (xmlFile.isDirectory()) {continue;}if (!FilenameUtils.isExtension(xmlFile.getAbsolutePath(), "xml")) {File failFolder = resourceService.getFile(fail);String path = failFolder.getAbsolutePath();String fileName = Utils.renameAndMove(xmlFile, path);logService.shipmentError(fail, fileName);logger.warn(String.format("It's not an XML file, filePath: %s", xmlFile.getAbsolutePath()));continue;}//check if file proceeded or notif(checkProcessFile(xmlFile.getName())) {processXml(xmlFile);}else {File failFolder = resourceService.getFile(fail);String path = failFolder.getAbsolutePath();String fileName = Utils.renameAndMove(xmlFile, path);logService.shipmentError(fail, fileName);}}}private boolean checkProcessFile(String fileName) {List<ShipmentPO> list=shipmentDao.findByFilename(fileName);if(CollectionUtils.isEmpty(list)) {return true;}for(ShipmentPO shipment:list) {if("W".equals(shipment.getStatus())||"C".equals(shipment.getStatus())){return false;}}return true;}public void processXml(File readFile) {Shipments shipments = null;try {FileInputStream inputStream = new FileInputStream(readFile);shipments = Utils.unmarshal(inputStream, Shipments.class);} catch (Exception e) {File failFolder = resourceService.getFile(fail);String path = failFolder.getAbsolutePath();String fileName = Utils.renameAndMove(readFile, path);logService.shipmentError(fail, fileName);return;}ShipmentPO po = shipmentToShipmentPO(shipments);po.setFilename(readFile.getName());saveShipment(po, shipments.getShipment());File successFolder = resourceService.getFile(success);String path = successFolder.getAbsolutePath();String newFileName = Utils.renameAndMove(readFile, path);logService.shipmentSuccess(success, newFileName);}@Transactionalprivate void saveShipment(ShipmentPO shipment, ShipmentType shipmentType) {ShipmentPO savedShipment = shipmentDao.save(shipment);populateOrders(savedShipment, shipmentType);}private ShipmentPO shipmentToShipmentPO(Shipments shipments) {ShipmentPO shipmentPo = new ShipmentPO();ShipmentType shipmentType = shipments.getShipment();populateShipment(shipmentPo, shipmentType);return shipmentPo;}private void populateShipment(ShipmentPO shipmentPo, ShipmentType shipmentType) {shipmentPo.setCarrier(shipmentType.getCarrier());shipmentPo.setCreatedate(new Date());shipmentPo.setShipmentNumber(shipmentType.getShipmentNumber());shipmentPo.setYear(shipmentType.getShipmentYear());shipmentPo.setStatus("W");if (StringUtils.isNoneBlank(shipmentType.getShipmentDate())) {try {Date date = DateUtils.parseDate(shipmentType.getShipmentDate(), "yyyy/MM/dd HH:mm:ss");shipmentPo.setShipmentDate(date);} catch (ParseException e) {System.out.println(shipmentType.getShipmentDate() + " is not like  'yyyy/MM/dd HH:mm:ss ' ");}}shipmentPo.setWarehouse(shipmentType.getWarehouseFrom());//populateOrders(shipmentPo, shipmentType);}private void populateOrders(ShipmentPO shipmentPo, ShipmentType shipmentType) {//ArrayList<OrderPO> orderList = new ArrayList<OrderPO>();SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");for (OrderType order : shipmentType.getOrders().getOrder()) {OrderPO po = new OrderPO();//po.setShipment(shipmentPo);po.setIcaId(shipmentPo.getId());po.setAddress(order.getAddress());po.setCity(order.getCity().toString());po.setCompanyName(order.getCompanyName());po.setCompanyName2(order.getCompanyName2());po.setCountry(order.getCountry());po.setIntordnum(order.getIntOrdNum());po.setOrderNumber(order.getOrderNumber());po.setBrand(order.getBrand());if (StringUtils.isNoneBlank(order.getDeliveryDate())) {try {Date deliveryDate = formatter.parse(order.getDeliveryDate());po.setDeliveryDate(deliveryDate);} catch (ParseException e) {System.out.println(order.getDeliveryDate() + " is not like  ' dd-MM-yyyy ' ");}}OrderPO savedOrder = orderDao.save(po);populateCartons(shipmentPo, savedOrder, order);// orderList.add(po);}//shipmentPo.setOrders(orderList);}private void populateCartons(ShipmentPO shipmentPo, OrderPO orderPo, OrderType order) {//ArrayList<CartonPO> cartonList = new ArrayList<CartonPO>();for (CartonType carton : order.getCartons().getCarton()) {CartonPO po = new CartonPO();po.setCartonNumber(carton.getCartonNumber());po.setHeight(Double.parseDouble(carton.getHeight()));po.setLength(Double.parseDouble(carton.getLength()));po.setQuantity(Double.parseDouble(carton.getQuantity()));po.setWeight(Double.parseDouble(carton.getWeight()));po.setWidth(Double.parseDouble(carton.getWidth()));//po.setShipment(shipmentPo);//po.setOrder(orderPo);po.setIcaId(orderPo.getIcaId());po.setIcoId(orderPo.getId());cartonDao.save(po);//cartonList.add(po);}//orderPo.setCartons(cartonList);}
}

1.3 最后只需启动springboot的启动类,系统将自动扫描目标文件解析xml文件或者运行ShipmentMonitorService的一个测试类也可以

主要测试类代码如下:

package com.ontop.job.geodis;import java.io.File;
import java.io.IOException;import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringRunner;import com.ontop.job.geodis.common.ResourceService;
import com.ontop.job.geodis.dao.ShipmentDao;
import com.ontop.job.geodis.monitor.ShipmentMonitorService;@SpringBootTest
@RunWith(SpringRunner.class)
public class ShipmentMonitorServiceTest {@Autowiredprivate ResourceService resource;@Autowiredprivate ShipmentMonitorService shipmentMonitorService;@Autowiredprivate ShipmentDao shipmentDao;@Test@Rollbackpublic void checkInputFileTest() throws IOException {TestCommon.clean(this.getClass().getClassLoader());System.out.println(shipmentDao.count());File rawFile = resource.getFile("classpath:\\xml\\xml\\BlueWave_20190727101739.xml");//        File rawFile = resource.getFile("classpath:\\xml\\xml\\error.xml");File beTest = resource.getFile("classpath:\\xml\\in");System.out.println(beTest.getAbsolutePath());//FileUtils.copyFile(rawFile, new File(beTest.getAbsolutePath() + "\\test.xml"));shipmentMonitorService.checkInputFile();long count = shipmentDao.count();System.out.println(count);//assertEquals(1, count);}
}

最后附上BlueWave_20190727101739.xml的内容

<?xml version="1.0" encoding="UTF-8"?>
<Shipments><Shipment><ShipmentNumber>21877</ShipmentNumber><ShipmentYear>2019</ShipmentYear><ShipmentDate>2019/07/27 10:17:37</ShipmentDate><Carrier>BWL - LTL</Carrier><Orders><Order><OrderNumber>3202622234</OrderNumber><Address>上海市青浦区沪青平公路2888号A区A102及A104店铺</Address><City /><State /><Zip>201704</Zip><Country /><IntOrdNum>198343</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海青浦</CompanyName><CompanyName2>Larry Lu</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>27-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222021</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>20.00</Height><Weight>0.00</Weight><Quantity>10.00</Quantity></Carton><Carton><CartonNumber>015222042</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>29.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622254</OrderNumber><Address>上海市浦东新区卓耀路58弄1-365号F11F12F13店铺</Address><City /><State /><Zip>200120</Zip><Country /><IntOrdNum>198360</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海浦东</CompanyName><CompanyName2>Betty Chen</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>28-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222012</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>5.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622252</OrderNumber><Address>上海市浦东新区卓耀路58弄1-365号F11F12F13店铺</Address><City /><State /><Zip>200120</Zip><Country /><IntOrdNum>198358</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海浦东</CompanyName><CompanyName2>Betty Chen</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>26-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222022</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>23.00</Quantity></Carton><Carton><CartonNumber>015222051</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>20.00</Quantity></Carton><Carton><CartonNumber>015222064</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>25.00</Quantity></Carton><Carton><CartonNumber>015222071</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>43.00</Quantity></Carton><Carton><CartonNumber>015222080</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>32.00</Quantity></Carton><Carton><CartonNumber>015222081</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>42.00</Quantity></Carton><Carton><CartonNumber>015222093</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>18.00</Quantity></Carton><Carton><CartonNumber>015222097</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>7.00</Quantity></Carton><Carton><CartonNumber>015222100</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>24.00</Quantity></Carton><Carton><CartonNumber>015222103</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>14.00</Quantity></Carton><Carton><CartonNumber>015222105</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>30.00</Quantity></Carton><Carton><CartonNumber>015302560</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015302563</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>10.00</Quantity></Carton><Carton><CartonNumber>015302569</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>13.00</Quantity></Carton><Carton><CartonNumber>015302570</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>10.00</Quantity></Carton><Carton><CartonNumber>015302576</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>9.00</Quantity></Carton><Carton><CartonNumber>015302581</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>10.00</Quantity></Carton><Carton><CartonNumber>015302584</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>14.00</Quantity></Carton><Carton><CartonNumber>015302592</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015302593</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>9.00</Quantity></Carton><Carton><CartonNumber>015302600</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>8.00</Quantity></Carton><Carton><CartonNumber>015302611</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>6.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622260</OrderNumber><Address>上海市浦东新区申迪东路88号M3.1店铺</Address><City /><State /><Zip /><Country /><IntOrdNum>198367</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海迪斯尼</CompanyName><CompanyName2>Cherry Zhu 13402029020</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>27-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222043</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>31.00</Quantity></Carton><Carton><CartonNumber>015222053</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>33.00</Quantity></Carton><Carton><CartonNumber>015222107</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>47.00</Quantity></Carton><Carton><CartonNumber>015222109</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>20.00</Height><Weight>0.00</Weight><Quantity>5.00</Quantity></Carton><Carton><CartonNumber>015302568</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>15.00</Quantity></Carton><Carton><CartonNumber>015302583</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>3.00</Quantity></Carton><Carton><CartonNumber>015302586</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>12.00</Quantity></Carton><Carton><CartonNumber>015302597</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>5.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622233</OrderNumber><Address>上海市青浦区沪青平公路2888号A区A102及A104店铺</Address><City /><State /><Zip>201704</Zip><Country /><IntOrdNum>198341</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海青浦</CompanyName><CompanyName2>Larry Lu</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>26-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222041</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>23.00</Quantity></Carton><Carton><CartonNumber>015222044</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>25.00</Quantity></Carton><Carton><CartonNumber>015222046</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>23.00</Quantity></Carton><Carton><CartonNumber>015222063</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>34.00</Quantity></Carton><Carton><CartonNumber>015222073</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>29.00</Quantity></Carton><Carton><CartonNumber>015222079</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015222086</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>32.00</Quantity></Carton><Carton><CartonNumber>015222095</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>15.00</Quantity></Carton><Carton><CartonNumber>015222098</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>29.00</Quantity></Carton><Carton><CartonNumber>015222099</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>20.00</Height><Weight>0.00</Weight><Quantity>5.00</Quantity></Carton><Carton><CartonNumber>015222101</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>16.00</Quantity></Carton><Carton><CartonNumber>015222106</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>24.00</Quantity></Carton><Carton><CartonNumber>015222242</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>28.00</Quantity></Carton><Carton><CartonNumber>015302558</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015302566</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>12.00</Quantity></Carton><Carton><CartonNumber>015302567</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>13.00</Quantity></Carton><Carton><CartonNumber>015302577</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>10.00</Quantity></Carton><Carton><CartonNumber>015302579</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015302582</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015302587</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015302588</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>12.00</Quantity></Carton><Carton><CartonNumber>015302594</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>11.00</Quantity></Carton><Carton><CartonNumber>015302595</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>10.00</Quantity></Carton><Carton><CartonNumber>015302598</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>13.00</Quantity></Carton><Carton><CartonNumber>015302612</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>8.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622235</OrderNumber><Address>上海市青浦区沪青平公路2888号A区A102及A104店铺</Address><City /><State /><Zip>201704</Zip><Country /><IntOrdNum>198342</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海青浦</CompanyName><CompanyName2>Larry Lu</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>28-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222011</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>5.00</Quantity></Carton><Carton><CartonNumber>015222023</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>30.00</Quantity></Carton><Carton><CartonNumber>015222026</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>5.00</Quantity></Carton><Carton><CartonNumber>015222028</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>9.00</Quantity></Carton><Carton><CartonNumber>015222039</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>7.00</Quantity></Carton><Carton><CartonNumber>015222049</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>9.00</Quantity></Carton><Carton><CartonNumber>015222055</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>10.00</Quantity></Carton><Carton><CartonNumber>015222056</CartonNumber><Length>40.00</Length><Width>30.00</Width><Height>20.00</Height><Weight>0.00</Weight><Quantity>1.00</Quantity></Carton><Carton><CartonNumber>015222061</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>63.00</Quantity></Carton><Carton><CartonNumber>015222068</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>35.00</Quantity></Carton><Carton><CartonNumber>015222089</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>62.00</Quantity></Carton><Carton><CartonNumber>015222161</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>17.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622259</OrderNumber><Address>上海市浦东新区申迪东路88号M3.1店铺</Address><City /><State /><Zip /><Country /><IntOrdNum>198365</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海迪斯尼</CompanyName><CompanyName2>Cherry Zhu 13402029020</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>26-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222018</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>25.00</Quantity></Carton><Carton><CartonNumber>015222047</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>38.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622261</OrderNumber><Address>上海市浦东新区申迪东路88号M3.1店铺</Address><City /><State /><Zip /><Country /><IntOrdNum>198368</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海迪斯尼</CompanyName><CompanyName2>Cherry Zhu 13402029020</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>28-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222006</CartonNumber><Length>40.00</Length><Width>30.00</Width><Height>20.00</Height><Weight>0.00</Weight><Quantity>7.00</Quantity></Carton><Carton><CartonNumber>015222088</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>45.00</Quantity></Carton><Carton><CartonNumber>015222110</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>57.00</Quantity></Carton></Cartons></Order><Order><OrderNumber>3202622253</OrderNumber><Address>上海市浦东新区卓耀路58弄1-365号F11F12F13店铺</Address><City /><State /><Zip>200120</Zip><Country /><IntOrdNum>198359</IntOrdNum><IntOrdYear>2019</IntOrdYear><CompanyName>AO.上海浦东</CompanyName><CompanyName2>Betty Chen</CompanyName2><Brand>Giorgio Armani Shanghai</Brand><DeliveryDate>27-07-2019</DeliveryDate><Cartons><Carton><CartonNumber>015222040</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>20.00</Height><Weight>0.00</Weight><Quantity>17.00</Quantity></Carton><Carton><CartonNumber>015222067</CartonNumber><Length>60.00</Length><Width>40.00</Width><Height>40.00</Height><Weight>0.00</Weight><Quantity>37.00</Quantity></Carton><Carton><CartonNumber>015302590</CartonNumber><Length>93.00</Length><Width>56.00</Width><Height>31.00</Height><Weight>0.00</Weight><Quantity>15.00</Quantity></Carton></Cartons></Order></Orders></Shipment>
</Shipments>

如何运用JAXB定时读取解析xml文件?相关推荐

  1. 使用QXmlStreamReader读取解析XML文件

    QXmlStreamReader QXmlStreamReader类通过简单的流式API为我们提供了一种快速的读取xml文件的方式.他比Qt自己使用的SAX解析方式还要快. 所谓的流式读取即将一个xm ...

  2. 安卓开发Android studio学习笔记12:读取解析XML(案例演示)

    Android studio学习笔记 第一步:配置Student.XML 第二步:配置activity_main.xml 第三步:配置student.xml 第四步:配置Student用户类 第五步: ...

  3. python读取xml_python解析xml文件

    加载和读取xml文件 import xml.dom.minidom doc = xml.dom.minidom.parse(xmlfile) 获取xml文档对象(对子节点和节点node都适用) roo ...

  4. jq ajax xml,jQuery+ajax读取并解析XML文件的方法

    本文实例讲述了jQuery+ajax读取并解析XML文件的方法.分享给大家供大家参考,具体如下: ajax.xml: zhangsan 1 lisi 2 demo.html: /p> " ...

  5. java解析xml文件:创建、读取、遍历、增删查改、保存

    全栈工程师开发手册 (作者:栾鹏) java教程全解 java使用JDOM接口解析xml文件,包含创建.增删查改.保存,读取等操作. 需要引入jdom.jar,下载 xercesImpl.jar,下载 ...

  6. tinyxml 读取文本节点_c++中用TINYXML解析XML文件

    TinyXML介绍 最近做一个负载均衡的小项目,需要解析xml配置文件,用到了TinyXML,感觉使用起来很容易,给出一个使用TinyXML进行XML解析的简单例子,很多复杂的应用都可以基于本例子的方 ...

  7. python读取xml标注坐标_遍历文件 创建XML对象 方法 python解析XML文件 提取坐标计存入文件...

    XML文件??? xml即可扩展标记语言,它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. 里面的标签都是可以随心所欲的按照他的命名规则来定义的,文件名为roi.xm ...

  8. SAX解析XML文件

    就目前来说,有三种方式可以解析XML文件:DOM.SAX.StAX.DOM将整个XML文件加载到内存中,并构建出节点树:应用程序可以通过遍历节点树的方式来解析XML文件中的各个节点.属性等信息:这种方 ...

  9. Android开发--详解SAX解析XML文件

    SAX技术字处理XML文件时并不是一次性把XML文件装入内存,而是一边读一边解析,因此,在解析的过程中会有几个步骤需要注意,在这里用一张图来表示解析的步骤: 在本实例中,定义了一个xml文件,其中有若 ...

最新文章

  1. Linux与Windows文件共享命令 rz,sz
  2. HTSRealistic missions 10:Holy Word High School
  3. 24张GIF图,让你秒懂非标自动化机构的原理
  4. 「GNN,简直太烂了」,一位Reddit网友的深度分析火了
  5. spreedrest
  6. JavaScript(笔记)
  7. Power Platform之Power Automate新增RPA功能
  8. opencomm在c语言中的作用,你能用C语言编写面向对象的代码吗?
  9. Java多线程学习二十四:阻塞队列包含哪些常用的方法?add、offer、put 等方法的区别?
  10. c语言怎么运行出星星,C语言打印星星的问题
  11. vs2010 打开项目卡死问题解决办法
  12. 模型压缩文献笔记_3:彩票假设及其家属。
  13. python实现微信自动投票_Python——开发一个自动化微信投票器【附代码实例方法】...
  14. R语言read.xlsx( )函数报错 LoadLibrary failure: %1 不是有效的 Win32 应用程序
  15. 工作多年想转行,有哪些正确的方法及技巧呢
  16. 素描如何避免抄调子?针对素描美术加建议这样学~
  17. JAVA基础学习20191-01-基础部分
  18. 金 融 量 化 分 析 • 外 篇 • 绘 制 行 情 数 据 数 据 图
  19. 软件跟踪调试破解心得
  20. 强化学习与ChatGPT:快速让AI学会玩贪食蛇游戏!

热门文章

  1. 知识与知识表示的概念
  2. 96年小哥哥的申请留学生免税车经历
  3. 华安财险规范经营战略
  4. 全新抖音运营技巧(建议收藏)
  5. Global Optimization via Optimal Decision Trees
  6. 怎样设置计算机u盘启动程序,怎样设置u盘启动|电脑设置u盘启动教程
  7. python int转化为字符串_将列表项从字符串转换为int(Python)
  8. 苹果服务器 系统安装教程视频,苹果安装win10系统图文教程
  9. 云原生中间件 -- MongoDB Operator 篇
  10. 计算机专业主题的实习报告7篇