- 浏览: 187255 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (83)
- J2EE/Core Java (24)
- J2EE/Portal (2)
- J2EE/UI (4)
- J2EE/ATG (1)
- J2EE/Report (1)
- J2EE/Web Service/Rest API (2)
- Design Pattern (2)
- Arithmetic (4)
- Linux (12)
- Ruby&Rails (17)
- Database (5)
- J2EE/Payment (1)
- J2EE/JVM (1)
- Encryption/Decryption (3)
- J2EE/Multi Threading (4)
- SQL (1)
- https://community.teamviewer.com/t5/Knowledge-Base/Where-can-I-download-older-TeamViewer-versions-nbsp/ta-p/7729 (0)
最新评论
引用
jaxb是一个读写xml的工具,还可以提供验证,不需要额外的jar
1. XSD sample
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org/draft_2/" targetNamespace="http://www.example.org/draft_2/"> <xs:complexType name="BaseCommonRefCType"> <xs:sequence> <xs:element name="name"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1" /> <xs:maxLength value="64" /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="type" maxOccurs="1" minOccurs="0"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1" /> <xs:maxLength value="64" /> <xs:enumeration value="filter" /> <xs:enumeration value="nzload" /> <xs:enumeration value="db_system" /> <xs:enumeration value="repetition_group" /> <xs:enumeration value="system_path" /> <xs:enumeration value="record" /> <xs:enumeration value="report" /> <xs:enumeration value="mapping" /> <xs:enumeration value="table" /> <xs:enumeration value="cob" /> <xs:enumeration value="file_container" /> <xs:enumeration value="node" /> <xs:enumeration value="instance" /> <xs:enumeration value="stage" /> <xs:enumeration value="java_config" /> <xs:enumeration value="business_date" /> <xs:enumeration value="matrix" /> <xs:enumeration value="database" /> <xs:enumeration value="file_pattern" /> <xs:enumeration value="gemfire_region" /> <xs:enumeration value="task" /> <xs:enumeration value="config_file" /> <xs:enumeration value="dataflow" /> <xs:enumeration value="ems" /> <xs:enumeration value="workflow" /> </xs:restriction> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> </xs:schema>
2. 根据xsd生成java类
xjc -p com.wilson test.xsd -d src
3. Sample class for retrieving classes from xml
public class JAXBUtil { private static final Log logger = LogFactory.getLog(JAXBUtil.class.getName()); public static YourClass retrieveObjectFromXML(File xml, URL xsdURL) { ProcessLifeCycle lifeCycle = null; JAXBContext jaxbContext; ValidationEventCollector vec = new ValidationEventCollector(); try { jaxbContext = JAXBContext.newInstance(YourClass.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); unmarshaller.setSchema(SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(xsdURL)); unmarshaller.setEventHandler(vec); lifeCycle = (ProcessLifeCycle) unmarshaller.unmarshal(xml); } catch (JAXBException e) { logger.error("", e); } catch (SAXException e) { logger.error("", e); } finally { if (vec != null && vec.hasEvents()) { for (ValidationEvent ve : vec.getEvents()) { String msg = ve.getMessage(); ValidationEventLocator vel = ve.getLocator(); int line = vel.getLineNumber(); int column = vel.getColumnNumber(); throw new RuntimeException("Can't unmarshal the XML file, error message: " + " At line " + line + ", column " + column + ": " + msg); } } } return lifeCycle; } }
发表评论
-
Start tomcat with port 80 without Linux root user-Use iptables mapping
2016-05-25 17:39 830引用In linux system. only root us ... -
Format XML in JAVA
2016-01-11 12:23 600public static String format ... -
HttpURLConnection下载文件
2015-08-07 11:25 792public class HttpDownloadUtilit ... -
Ehcache RMI Replicated Cluster(RMI集群)
2013-04-25 23:39 1067引用本文是ehcache RMI集群的例子,导入附件中的jav ... -
Integrete unitils for database(dao) testing
2013-02-01 18:39 1691引用Database testing Unit tests f ... -
Freemarker使用入门
2012-10-16 11:54 1017引用freemarker是一种模板标记工具,可以做页面静态化, ... -
perforce java api使用
2012-10-16 11:43 1253引用perforce是种版本管理软件,提供啦完整的java a ... -
XPath 入门
2012-10-16 11:29 878引用xpath可以快速定位获取XML文件中指定属性和值,jdk ... -
Java File Diff-diffutils
2012-09-27 17:35 74441. Maven Dependency <depende ... -
XSD 入门使用
2012-09-18 23:20 774<?xml version="1.0" ... -
nexus-2.1.1安装及使用入门
2012-08-13 22:52 14441. 安装 地址http://www.sonatype.org ... -
File Demo
2012-06-25 22:55 1307package org.springside.examples ... -
Java 访问sharepoint webservice(NTLM & SSL)
2012-06-12 09:47 3771引用遇到需要使用java访问微软的sharepoint的web ... -
Selenium Web Driver入门
2012-05-27 23:17 58351 What is Selenium? 引用Selenium ... -
HttpClient4.1.2 & HtmlUnit2.9 处理文件下载
2012-01-09 18:18 1023TestCode import java.io.Fi ... -
HttpClient4.1.2 & HtmlUnit2.9 NTLM 验证 和 Httpclient4.1.2 https/SSL
2012-01-09 18:13 15941. HttpClient4.1.2 & HtmlUn ... -
HttpClient4登陆ITeye
2012-01-08 23:33 1895import java.io.IOException; im ... -
Spring2集成测试
2011-08-25 22:21 761Spring2测试类继承层次 集成测试例子 public ... -
Learning EasyMock3.0 By Official Example
2011-08-24 16:48 1374Maven Installation+ add followi ... -
Maven+jetty+jrebel+m2eclipse+eclipse搭建struts2开发环境
2011-08-11 11:18 4119引用Maven:项目构建工具,通过pom.xml可以自动维护j ...
相关推荐
很好的jaxb入门示例 把所有注解标签都试一遍基本就OK了
NULL 博文链接:https://popomonkey.iteye.com/blog/688580
这是一个不错的文档哦,希望能下下来参考看看
NULL 博文链接:https://rensanning.iteye.com/blog/2378681
资料比较完整:Jaxb2_技术指南,JAXB的使用入门,JAXB介绍.ppt,JAXBDemos
JiBx又一个不错的xml绑定工具,和jaxb等一样,都是属于xml绑定工具。而JiBx使用java字节码enhance技术,不像jaxb等更多在于源代码生成技术。JiB的工作主要在于前期,也就是进行字节码绑定,这一部分基本上都是在...
WebService CXF学习——入门篇 1.CXF由来 2.HelloWorld 3.WSDL描述 WebService CXF学习——进阶篇 1.SOAP讲解 2.JAX-WS讲解 3.对象传递 WebService CXF学习——高级篇(一)(二) 1.整合Spring框架 2.CXF...
入门安装节点和NPM 和才能运行测试。运行测试$ npm test示例输出$ npm test> json-tf@1.0.0 test /Users/sallen/Projects/Demo/JSON-TF> mocha xStudentsGoessner.json #familyName ✓ should find "Lovell" as ...
9.2.2 我的联系手册(JAXB实现) 238 9.3 小结 242 第10章 准备环球旅行——应用程序国际化 243 10.1 讲解 244 10.1.1 概念介绍 244 10.1.2 设置Locale 249 10.1.3 隔离语言环境相关数据 252 10.1.4 格式化 ...
14.3.1 JAXB 14.3.2 XMLBeans 14.3.3 Castor 14.3.4 JiBX 14.3.5 总结比较 14.4 与Spring OXM整合 14.4.1 Spring OXM概述 14.4.2 整合OXM实现者 14.4.3 如何在Spring中进行配置 14.4.4 Spring OXM 简单实例 14.5 小...
14.3.1 JAXB 14.3.2 XMLBeans 14.3.3 Castor 14.3.4 JiBX 14.3.5 总结比较 14.4 与Spring OXM整合 14.4.1 Spring OXM概述 14.4.2 整合OXM实现者 14.4.3 如何在Spring中进行配置 14.4.4 Spring OXM 简单实例 14.5 小...