---
title: "JAXB JAXP Miscellaneous"
author: "adapterofcoms"
date: "2015-03-07T21:12:03Z"
tags: []
categories: ["Web前端"]
slug: "jaxb-jaxp-miscellaneous"
draft: false
lastmod: "2015-03-07T21:12:03Z"
id: 2190375
url: "https://adapterofcoms.iteye.com/blog/2190375"
---

schemegen  
xjc  
C:\\jdk1.8.0\_25\\bin\\java -Dfile.encoding=UTF-8 -cp C:\\jdk1.8.0\_25\\lib\\tools.jar com.sun.tools.internal.xjc.Driver -d . -p com.\*.smodel \*.xsd

C:\\jdk1.8.0\_25\\bin\\xjc -encoding UTF-8 -d . -p com.\*.smodel \*.xsd

marshaller.setProperty(Marshaller.JAXB\_ENCODING, "UTF-8");// //编码格式  
marshaller.setProperty(Marshaller.JAXB\_FORMATTED\_OUTPUT, true);// 是否格式化生成的xml串 ，这是不可靠的！！！  
marshaller.setProperty(Marshaller.JAXB\_FRAGMENT, false);// 是否省略xm头声明信息

http://blog.sina.com.cn/s/blog\_6fda308501013w2a.html  
http://iteye.blog.163.com/blog/static/186308096201211137371297/  
http://dacoolbaby.iteye.com/blog/1667283

JAXBContext:  
To avoid the overhead involved in creating a JAXBContext instance, a JAXB  
application is encouraged to reuse a JAXBContext instance. An implementation  
of abstract class JAXBContext is required to be **thread-safe**, thus, multiple  
threads in an application can share the same JAXBContext instance.

**contextPath**:  packages "com.acme.foo:com.acme.bar"  all exists the **ObjectFactory** ?  
**classes**: \[...]

A package consists of:  
...  
A public class **ObjectFactory**  
...

@XmlRootElement

@XmlElement  
@XmlAttribute

List&lt;JAXBElement&lt;T&gt;&gt; getContent()

@XmlAnyElement(lax = true)  
List&lt;java.lang.Object&gt; any;   how?  
1.ObjectFactory +:  
@XmlElementDecl(name="entity",namespace="", scope = Entity.class)  
public JAXBElement&lt;Entity&gt; createEntity(Entity e)  
OR  
public Entity createEntity() {return new Entity();}  
2.Entity +: @XmlRootElement  
http://www.myexception.cn/xml-soap/1780642.html

**formatted via JAXP Transformer, DONT depends on the JAXB\_FORMATTED\_OUTPUT.**

@XmlElement(required = true, **type=X.class**)   marshalling dont generate the Attributes \[xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:X.class.Name"]  
java.lang.**Object** member;