<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.4</version>
</dependency>
<?xml version="1.0" encoding="UTF-8"?>
<com.yundaex.wms.core.store.po.RivQuant>
<qtId>-1</qtId>
<qtAllocQty>100</qtAllocQty>
<qtBillId>25</qtBillId>
<qtBillType>1</qtBillType>
<qtContainerId>11</qtContainerId>
<qtContainerTypeId>19</qtContainerTypeId>
<qtLocationId>10</qtLocationId>
<qtLotItem1>22</qtLotItem1>
<qtLotItem2>12</qtLotItem2>
<qtLotItem3>12</qtLotItem3>
<qtLotNo></qtLotNo>
<qtLotString1></qtLotString1>
<qtLotString2></qtLotString2>
<qtLotString3></qtLotString3>
<qtLotString4></qtLotString4>
<qtLotString5></qtLotString5>
<qtLpn></qtLpn>
<qtMaterialId>17</qtMaterialId>
<qtMaterialStatusId>8</qtMaterialStatusId>
<qtOnhandQty>100</qtOnhandQty>
<qtOnrecvQty>100</qtOnrecvQty>
<qtOrgId>49</qtOrgId>
<qtOwnerId>19</qtOwnerId>
<qtTrolleyCellNo></qtTrolleyCellNo>
<qtType>location</qtType>
<qtVoucherNo>123456</qtVoucherNo>
<versionNumber>0</versionNumber>
</com.yundaex.wms.core.store.po.RivQuant>
import java.io.IOException;
import java.io.InputStream; import org.apache.commons.lang.StringUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import com.thoughtworks.xstream.XStream; public class Xml2Object { private static XStream xstream; static {
xstream = new XStream();
} public static Object convert2Object(String xmlName) {
String configPath = "classpath*:data/"+xmlName;
//String path = Xml2Object.class.getResource("/").getPath() + xmlName;
InputStream inputStream = null;
try {
final int index = StringUtils.lastIndexOf(configPath, ":") == -1 ? 0 : StringUtils.lastIndexOf(configPath, ":");
final Resource resource = new ClassPathResource(StringUtils.substring(configPath, index+1, configPath.length()));
inputStream = resource.getInputStream();
} catch (Exception e) {
e.printStackTrace();
}
Object obj = xstream.fromXML(inputStream);
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return obj;
} public static void main(String[] args) {
convert2Object("owner.xml");
}
}

Xml2Object的更多相关文章

  1. java生成解析xml的另外两种方法JAXB

     JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实例文档反 ...

  2. java学习之xml

    xml的处理有两种方式dom和Sax 其中dom有3套api ,分别是dom和jdom和dom4j package com.gh.xml; import java.io.File; import ja ...

  3. xml转对象,对象转xml工具类

    package com.dq.schooldomain.utils; import com.thoughtworks.xstream.XStream; import com.thoughtworks. ...

  4. Noname

    版本: LayaAir IDE 2.0.1beta laya.core.js ___Laya ColorUtils LayaGLQuickRunner DrawTextureCmd Point Col ...

  5. [CXF REST标准实战系列] 一、JAXB xml与javaBean的转换

    Writer:BYSocket(泥沙砖瓦浆木匠) 微博:BYSocket 豆瓣:BYSocket Reprint it anywhere u want. 文章Points: 1.不认识到犯错,然后得到 ...

  6. 微信扫码支付springboot版本

    发布时间:2018-11-06   技术:springboot+freemarker   概述 该项目是一个采用springboot构建的web项目,主要实现了微信扫码支付功能.包含最基本的创建订单, ...

  7. [CXF REST标准实战系列] 一、JAXB xml与javaBean的转换(转)

    转自:[CXF REST标准实战系列] 一.JAXB xml与javaBean的转换 文章Points: 1.不认识到犯错,然后得到永久的教训. 2.认识JAXB 3.代码实战 1.不认识到犯错,然后 ...

  8. xml生成javabean(zhuan)

    package com.dom4j; import java.io.File;import java.io.FileWriter;import java.io.IOException;import j ...

  9. [android] 天气app布局练习(四)

    主要练习一下获取网络数据和解析xml MainActivity.java package com.example.weatherreport; import java.io.UnsupportedEn ...

随机推荐

  1. bzoj 2632 [ neerc 2011 ] Gcd guessing game —— 贪心

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2632 官方题解:http://neerc.ifmo.ru/archive/2011/neer ...

  2. 杂项:Code(开源资源)

    ylbtech-杂项:Code(开源资源) 1.返回顶部 1.CSDN http://code.csdn.net/ 2.腾讯·开源 http://code.tencent.com/ 3. 4. 5. ...

  3. Spring boot 学习二:入门

    1: 需要的环境: JDK:至少JDK7才支持Spring boot maven:至少3.2 spring-boot:1.2.5.RELEASE(在pom.xml中指定) 2: 创建一个maven工程 ...

  4. CSS3新增的伪类

    Element1 ~ element2:选择前面有element1的所有element2元素 [attr ^= val] 属性值以val开头的元素 [attr $= val] 属性值以val结尾的元素 ...

  5. MS-SQL使用xp_cmdshell命令导出数据到excel

    exec master..xp_cmdshell 'bcp "select c.Category_Title as 标题,p.Category_Title as 所属分类 from ltbl ...

  6. IPC编程之消息队列

    本地的进程间通信(IPC)有很多种方式,但可以总结为下面3类: 1.消息传递(管道.FIFO.消息队列) 2.同步(互斥量.条件变量.读写锁.文件和写记录锁.信号量) 3.共享内存(匿名的和具名的) ...

  7. Spring入门第四课

    注入参数详解:null值和级联属性 可以使用专用的<null/>元素标签为Bean的字符串或其他对象类型的属性注入null值. 和Struts,Hiberante等框架一样,Spring支 ...

  8. Ubuntu12.04 上使用perl snmpwalk问题

    今天在Ubuntu12.04上使用perl来获取snmp数据,运行时出现下列问题.解决方法安装一下libnet-snmp-perl即可.命令行运行:sudo apt-get install libne ...

  9. spring framework 源码

    spring framework 各版本源码下载地址 现在spring的源码下载地址真是不好找,这次终于找到了.记录一下,以帮助需要的朋友. https://github.com/spring-pro ...

  10. python 学习笔记12(事件驱动、IO多路复用、异步IO)

    阻塞IO和非阻塞IO.同步IO和异步IO的区别 讨论背景:Linux环境下的network IO. 1.先决条件(几个重要概念) 1.1.用户空间与内核空间 现在操作系统都是采用虚拟存储器,那么对32 ...