A simple approach for unmarshalling an XML document consists of the creation of a JAXB context and the call to unmarshal the document. A JAXBContext object provides the entry point to the JAXB API and maintains the binding information between XML and Java. One way of creating a context instance is by calling the static method newInstance with a list of colon separated names of the packages containing the JAXB schema-derived classes. From this context, an Unmarshaller object is obtained, which functions as the driver for processing an XML text to create the equivalent set of Java objects. It offers several unmarshal methods, accepting a wide range of object types as the source for XML text data. The method shown below illustrates this with a single package containing the class of the type defining the top level element of the XML document.

public <T> T unmarshal( Class<T> docClass, InputStream inputStream )
throws JAXBException {
String packageName = docClass.getPackage().getName();
JAXBContext jc = JAXBContext.newInstance( packageName );
Unmarshaller u = jc.createUnmarshaller();
JAXBElement<T> doc = (JAXBElement<T>)u.unmarshal( inputStream );
return doc.getValue();
}

The return value of the call to JAXB's unmarshal is a representation of the root node of the parsed XML document in an instance of JAXBElement<T>. If we're not interested in the tag of the root element we might just as well return the extracted content value.

JAXB - Unmarshalling的更多相关文章

  1. JAXB XML到java object的转换

    JAXB是Java Architecture for XML Binding的缩写.使用JAXB注解将Java对象转换成XML文件.在这篇教程中,我们将会展示如何使用JAXB来做以下事情: 1. ma ...

  2. Table of Contents - JAXB

    Getting Started Hello World Hello World with Namespace xjc - 将 XML Schema 编译成 Java 类 wsimport: 编译 WS ...

  3. JAXB - Annotations, Type Adapters: XmlJavaTypeAdapter

    For some Java container types JAXB has no built-in mapping to an XML structure. Also, you may want t ...

  4. org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"", local:"mixornot")。

    三月 09, 2018 3:09:14 下午 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging警告: Interceptor fo ...

  5. org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:"", local:"werks")。所需元素为(none)

    警告: Interceptor for {http://impl.service.ws.cxf.com/}WsStkoServiceImplService#{http://service.ws.cxf ...

  6. XmlRootElement JAXB

    http://desert3.iteye.com/blog/1570092(文章已经很好) 看了那边文章以后尝试后写点直白的 PROPERTY: JAXB 绑定类中的每个获取方法/设置方法对将会自动绑 ...

  7. 错误:java.util.Map is an interface, and JAXB can't handle interfaces.

    问题: 在整合spring+cxf时报错java.util.Map is an interface, and JAXB can't handle interfaces. 解决方法: 将服务端的serv ...

  8. jaxb

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

  9. Jaxb annotation使用

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

随机推荐

  1. MATLAB绘图与图形处理

    参考:http://www.cnblogs.com/djcsch2001/tag/MATLAB/  matlab部分写的不错! 7.2  三维图形 7.2.1  三维曲线.面填色命令 命令1  com ...

  2. HW5.31

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  3. algorithm@ 大素数判定和大整数质因数分解

    #include<stdio.h> #include<string.h> #include<stdlib.h> #include<time.h> #in ...

  4. Ubuntu 14.04.3 LTS 配置 DNS Server

    我们目的是用一台局域网机器完成 192.168.1.113 <-->cloudshield.com的解析,指定A记录和CNAME; 0.关于Ubuntu 14.04.2 LTS 下载.安装 ...

  5. 基于XML数据库的学生信息管理系统的设计与实现

    本项目是在学习之余写的,主要用来练习MVC+DAO的分层设计思想,项目基于一个简单的XML学生数据库,使用XML作为数据库的原因是其十分的小巧与方便,使用dom4j即可进行方便的解析.因为这段时间课程 ...

  6. MySQL数据库备份还原(基于binlog的增量备份)

    MySQL数据库备份还原(基于binlog的增量备份) 一.简介 1.增量备份      增量备份 是指在一次全备份或上一次增量备份后,以后每次的备份只需备份与前一次相比增加或者被修改的文件.这就意味 ...

  7. libpq程序例子

    程序: [root@lex tst]# cat testlibpq.c /* * testlibpq.c * Test the C version of LIBPQ, the POSTGRES fro ...

  8. UIView的Touch事件UIControlEvents详解

    首先,UIControlEvents有这个几种: UIControlEventTouchDown = << , // on all touch downs UIControlEventTo ...

  9. 【转】linux下cppunit的安装

    以下内容来自:http://www.51testing.com/html/51/279751-170160.html 1. 安装 cppunit的下载地址为:http://sourceforge.ne ...

  10. lightoj1104(数学概率与期望)

    题意: 增加一年有n天; 那么至少有几个人,能够保证至少两个人同一天生日的概率大于等于0.5; 思路: 转化一下题意; 就是求全部人生日都不同的概率小于等于0.5(那么至少两个人同一天就是大于等于0, ...