- 浏览: 194763 次
- 性别:
- 来自: 苏州
文章分类
最新评论
-
hyqaxxs:
果然如此
jQuery UI dialog插件出错信息:$(this).dialog is not a function -
Rhao:
厉害 我的也是这样子 终于好了
jQuery UI dialog插件出错信息:$(this).dialog is not a function -
ruyi0127:
三炮 被你骗了
oracle sqldeveloper设置自动提示 -
lt26i:
有问题,删除了当前页面的引用其他需要引用的地方报错,用了这个方 ...
jQuery UI dialog插件出错信息:$(this).dialog is not a function -
353386051:
...
禁用密码文本框的粘贴复制功能
a.xml
a.xsd
xjc生成java类
D:\JavaSoft\jdk6\bin>xjc -d f:/xmldemo -p demo.xml f:/xmldemo/a.xsd
parsing a schema...
compiling a schema...
demo\xml\Address.java
demo\xml\Customer.java
demo\xml\ObjectFactory.java
Customer.java
Address.java
ObjectFactory.java
JaxbDemo.java
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <customer id="cust id"> <address> <street>jinjihulu</street> <city>suzhou</city> <zip>215200</zip> </address> <name>Marshall</name> </customer>
a.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="Customer"> <xs:sequence> <xs:element name="address" type="Address"/> <xs:element name="name" type="xs:string"/> </xs:sequence> <xs:attribute name="id" type="xs:string"/> </xs:complexType> <xs:complexType name="Address"> <xs:sequence> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="zip" type="ZipCodeType"/> </xs:sequence> </xs:complexType> <xs:simpleType name="ZipCodeType"> <xs:restriction base="xs:integer"> <xs:minInclusive value="10000"/> <xs:maxInclusive value="99999"/> </xs:restriction> </xs:simpleType> <xs:element name="customer" type="Customer"/> <xs:element name="address" type="Address"/> </xs:schema>
xjc生成java类
D:\JavaSoft\jdk6\bin>xjc -d f:/xmldemo -p demo.xml f:/xmldemo/a.xsd
parsing a schema...
compiling a schema...
demo\xml\Address.java
demo\xml\Customer.java
demo\xml\ObjectFactory.java
Customer.java
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2011.12.30 at 04:13:13 PM CST // package demo.xml; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for Customer complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType name="Customer"> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="address" type="{}Address"/> * <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/> * </sequence> * <attribute name="id" type="{http://www.w3.org/2001/XMLSchema}string" /> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Customer", propOrder = { "address", "name" }) public class Customer { @XmlElement(required = true) protected Address address; @XmlElement(required = true) protected String name; @XmlAttribute protected String id; /** * Gets the value of the address property. * * @return * possible object is * {@link Address } * */ public Address getAddress() { return address; } /** * Sets the value of the address property. * * @param value * allowed object is * {@link Address } * */ public void setAddress(Address value) { this.address = value; } /** * Gets the value of the name property. * * @return * possible object is * {@link String } * */ public String getName() { return name; } /** * Sets the value of the name property. * * @param value * allowed object is * {@link String } * */ public void setName(String value) { this.name = value; } /** * Gets the value of the id property. * * @return * possible object is * {@link String } * */ public String getId() { return id; } /** * Sets the value of the id property. * * @param value * allowed object is * {@link String } * */ public void setId(String value) { this.id = value; } }
Address.java
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2011.12.30 at 04:13:13 PM CST // package demo.xml; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; /** * <p>Java class for Address complex type. * * <p>The following schema fragment specifies the expected content contained within this class. * * <pre> * <complexType name="Address"> * <complexContent> * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType"> * <sequence> * <element name="street" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="city" type="{http://www.w3.org/2001/XMLSchema}string"/> * <element name="zip" type="{}ZipCodeType"/> * </sequence> * </restriction> * </complexContent> * </complexType> * </pre> * * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "Address", propOrder = { "street", "city", "zip" }) public class Address { @XmlElement(required = true) protected String street; @XmlElement(required = true) protected String city; protected int zip; /** * Gets the value of the street property. * * @return * possible object is * {@link String } * */ public String getStreet() { return street; } /** * Sets the value of the street property. * * @param value * allowed object is * {@link String } * */ public void setStreet(String value) { this.street = value; } /** * Gets the value of the city property. * * @return * possible object is * {@link String } * */ public String getCity() { return city; } /** * Sets the value of the city property. * * @param value * allowed object is * {@link String } * */ public void setCity(String value) { this.city = value; } /** * Gets the value of the zip property. * */ public int getZip() { return zip; } /** * Sets the value of the zip property. * */ public void setZip(int value) { this.zip = value; } }
ObjectFactory.java
// // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2011.12.30 at 04:13:13 PM CST // package demo.xml; import javax.xml.bind.JAXBElement; import javax.xml.bind.annotation.XmlElementDecl; import javax.xml.bind.annotation.XmlRegistry; import javax.xml.namespace.QName; /** * This object contains factory methods for each * Java content interface and Java element interface * generated in the generated package. * <p>An ObjectFactory allows you to programatically * construct new instances of the Java representation * for XML content. The Java representation of XML * content can consist of schema derived interfaces * and classes representing the binding of schema * type definitions, element declarations and model * groups. Factory methods for each of these are * provided in this class. * */ @XmlRegistry public class ObjectFactory { private final static QName _Address_QNAME = new QName("", "address"); private final static QName _Customer_QNAME = new QName("", "customer"); /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: generated * */ public ObjectFactory() { } /** * Create an instance of {@link Customer } * */ public Customer createCustomer() { return new Customer(); } /** * Create an instance of {@link Address } * */ public Address createAddress() { return new Address(); } /** * Create an instance of {@link JAXBElement }{@code <}{@link Address }{@code >}} * */ @XmlElementDecl(namespace = "", name = "address") public JAXBElement<Address> createAddress(Address value) { return new JAXBElement<Address>(_Address_QNAME, Address.class, null, value); } /** * Create an instance of {@link JAXBElement }{@code <}{@link Customer }{@code >}} * */ @XmlElementDecl(namespace = "", name = "customer") public JAXBElement<Customer> createCustomer(Customer value) { return new JAXBElement<Customer>(_Customer_QNAME, Customer.class, null, value); } }
JaxbDemo.java
package demo.xml; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.OutputStream; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; public class JaxbDemo { public static void main(String[] args) throws Exception { unmarshalling(); marshalling(); } static void unmarshalling() throws Exception{ JAXBContext jc = JAXBContext.newInstance("demo.xml"); Unmarshaller u = jc.createUnmarshaller(); JAXBElement customerE = (JAXBElement) u.unmarshal(new FileInputStream( "F:\\xmldemo\\a.xml")); Customer bo = (Customer) customerE.getValue(); System.out.println(bo.getName() + " : " + bo.getAddress().getCity() + " : " + bo.getId()); } static void marshalling()throws Exception{ JAXBContext jc = JAXBContext.newInstance(Customer.class); Marshaller ms = jc.createMarshaller(); ms.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); Customer cust = new Customer(); cust.setId("cust id"); cust.setName("Marshall"); Address a = new Address(); a.setCity("suzhou"); a.setStreet("jinjihulu"); a.setZip(215200); cust.setAddress(a); OutputStream os = new FileOutputStream("F:\\xmldemo\\a.xml"); ms.marshal(cust, os); os.close(); } }
发表评论
-
[Java]XML与Properties
2011-12-30 14:04 1321package demo.xml; import j ... -
Java内存模型
2011-11-16 17:15 894一、 java内存结构 ... -
[JSE]商业计算中Java高精度计算BigDecimal类
2011-11-14 10:32 2443如果我们编译运行下面这个程序会看到什么? public c ... -
[java]jdk反编译器
2011-09-02 13:15 1589javap -c package.ClassName / ... -
[java][String]JavaSE5/6中的String
2011-08-31 09:44 0一.不可变 String类中每一个看起来会修改String ... -
[java][io][Serialize]对象序列化,Externalizable
2011-04-21 14:05 1261import java.io.EOFException ... -
[java][io][Serialize]对象序列化
2011-04-20 17:40 1198import java.io.FileInputS ... -
[java][io][ZIP]用ZIP保存多个文件
2011-04-20 16:41 2639Java对Zip格式类库支持得比较全面,得用它可以把多个文件压 ... -
[java][io][ZIP]使用GZIP进行压缩和解压缩
2011-04-20 10:54 1294Checksum 接口:被类Adler32和CRC32实现的接 ... -
[java][nio]映射文件部分加锁
2011-04-19 15:39 1102import java.io.RandomAccess ... -
[java][nio]文件加锁
2011-04-18 18:08 1245import java.io.FileOutputSt ... -
[java][nio]Stream与MappedByteBuffer的性能比较
2011-04-18 17:16 2225import java.io.BufferedInpu ... -
[java][nio]MappedByteBuffer修改大文件
2011-04-18 15:15 3111import java.io.FileNotFound ... -
[java][nio]Buffer的get, put, get(index), put(index)
2011-04-18 13:28 2160import java.nio.ByteBuffer; ... -
[java][nio]用Buffer操纵数据
2011-04-18 13:14 1009import java.nio.ByteBuffer; ... -
[java][nio]字节存放秩序
2011-04-18 10:18 910import java.nio.ByteBuffer; ... -
[java][nio]视图缓冲器
2011-04-18 09:52 1051import java.nio.ByteBuffer; ... -
[java][nio]IntBuffer
2011-04-15 11:00 1224import java.nio.ByteBuffer; ... -
[java][nio]从ByteBuffer中获取基本数据类型
2011-04-15 10:25 5078import java.nio.ByteBuffe ... -
[java][nio]查看Charset可用的字符集
2011-04-14 18:43 1056import java.nio.charset.Cha ...
相关推荐
JAXB工具类 xml转为java对象 java对象转为xml ,本人亲测,可以使用!!!
NULL 博文链接:https://xiongpan0807.iteye.com/blog/1832124
使用java jdk的JAXB技术实现xml与java对象互相转化代码教程: JDK中JAXB相关的重要Class和Interface:(来源于百度百科JAXB) •JAXBContext类,是应用的入口,用于管理XML/Java绑定信息。 •Marshaller接口,将Java...
Java XML绑定架构(JAXB)提供了一个绑定编译器,xjc,来从一个XML模式中生成Java类。用JAXB的xjc生成的Java类代表了在XML模式中不同的元素和复杂类型(complexType)。(一个复杂类型通过指定属性和元素内的元素来提供对...
JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术。该过程中,JAXB也提供了将XML实例文档反向生成Java对象树的方法,并能将Java对象树的内容重新写到XML实例...
编写xsd文件,利用jaxb生成java类。
NULL 博文链接:https://luyuwww.iteye.com/blog/1988355
JAXB XML TO JAVA,文件转化 生成java代码
本文系原创,如需转载请注明作者...本文详细介绍了Java XML绑定技术,并重点说明了如果使用JAXB来简化XML文档的操作。如果你的Java项目中需要使用XML(作为配置文件或数据库),不妨试一下JAXB,你一定会有惊喜的发现。
THE Java™Architecture for XML Binding (JAXB) provides a fast and convenient way to bind between XML schemas and Java representations, making it easy for Java developers to incorporate XML data and ...
《Java与XML》(第三版)的内容涵盖了所有主要的Java XML处理库程序,全面讲解了SAX、DOM、StAX、JDOM以及dom4j的应用程序编程接口,同时还囊括了最新版本的用于XML处理的Java应用程序编程接口(JAXP)和用于XML绑定...
JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术。JAXB与xml相互转换实例。
《Java与XML》(第三版)的内容涵盖了所有主要的Java XML处理库程序,全面讲解了SAX、DOM、StAX、JDOM以及dom4j的应用程序编程接口,同时还囊括了最新版本的用于XML处理的Java应用程序编程接口(JAXP)和用于XML绑定...
Java 解析XML性能分析Demo。包含了DOM解析,SAX解析, JDOM解析,DOM4J解析,JAXB解析例子。
jaxb将xml转换为对象或将对象转换为xml。测试通过。
JAXB_2.2_API.chm,Java+XML绑定技术.doc JAXB_2.2_API.chm,Java+XML绑定技术.doc JAXB_2.2_API.chm,Java+XML绑定技术.doc JAXB_2.2_API.chm,Java+XML绑定技术.doc JAXB_2.2_API.chm,Java+XML绑定技术.doc JAXB_2.2_...
jaxb 将xml里面的对象转化为一个个类,大大地简化了xml的相关操作。unmarshal marshal
JAXB注解 java 关于xml的注解,自动生成xml文件
NULL 博文链接:https://rayoo.iteye.com/blog/1233534
java 使用 JAXB 将xml转换为 bean 包含xml和dto和读取文件的util类