您将需要使用
XmlAdapter此用例。下面是一个示例绑定文件,可以帮助您生成它们。逻辑将包含在一个
DecimalFormatter类中,该类包含用于所有不同所需格式的方法。
<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1"> <jxb:bindings schemaLocation="schema.xsd"> <jxb:bindings node="//xs:element[@name='amount']"> <jxb:property> <jxb:baseType> <jxb:javaType name="java.math.BigDecimal" parseMethod="org.example.DecimalFormatter.parseDecimal" printMethod="org.example.DecimalFormatter.printDecimal_2Places" /> </jxb:baseType> </jxb:property> </jxb:bindings> <jxb:bindings node="//xs:element[@name='rate']"> <jxb:property> <jxb:baseType> <jxb:javaType name="java.math.BigDecimal" parseMethod="org.example.DecimalFormatter.parseDecimal" printMethod="org.example.DecimalFormatter.printDecimal_5Places" /> </jxb:baseType> </jxb:property> </jxb:bindings> </jxb:bindings></jxb:bindings>
想要查询更多的信息
- http://blog.bdoughan.com/2011/08/xml-schema-to-java-generating.html



