java中提供了xjc.exe可以将xds转成类方法,但是用命令行导CDA.xds是报如下错误:
Exception in thread "main"java.lang.IllegalArgumentException:tryingtocreatethesamefieldtwice:id
at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:419)
at com.sun.codemodel.JDefinedClass.field(JDefinedClass.java:390)
at com.sun.tools.xjc.generator.bean.field.AbstractFieldWithVar.createField(AbstractFieldWithVar.java:71)
at com.sun.tools.xjc.generator.bean.field.SingleField.(SingleField.java:89)
at com.sun.tools.xjc.generator.bean.field.SingleField.(SingleField.java:76)
at sun.reflect.GeneratedConstructorAccessor10.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
atjava.lang.reflect.Constructor.newInstance(Unknown Source)
at com.sun.tools.xjc.generator.bean.field.GenericFieldRenderer.generate(GenericFieldRenderer.java:64)
at com.sun.tools.xjc.generator.bean.field.DefaultFieldRenderer.generate(DefaultFieldRenderer.java:75)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateFieldDecl(BeanGenerator.java:744)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generateClassBody(BeanGenerator.java:532)
at com.sun.tools.xjc.generator.bean.BeanGenerator.(BeanGenerator.java:234)
at com.sun.tools.xjc.generator.bean.BeanGenerator.generate(BeanGenerator.java:174)
at com.sun.tools.xjc.model.Model.generateCode(Model.java:286)
at com.sun.tools.xjc.Driver.run(Driver.java:343)
at com.sun.tools.xjc.Driver.run(Driver.java:191)
at com.sun.tools.xjc.Driver._main(Driver.java:116)
at com.sun.tools.xjc.Driver.access$000(Driver.java:74)
at com.sun.tools.xjc.Driver$1.run(Driver.java:96)
原来是ID和id在Java中冲突所致,参考了一篇技术文档搞定。
1)在源POCD_MT000040.xsd文件中
ID" type="xs:ID">
替换成:
ID" type="xs:ID">
ID1">
2)在源POCD_MT000040.xsd头中添加
xmlns:mif="urn:hl7-org:v3/mif"
xmlns="urn:hl7-org:v3"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
elementFormDefault="qualified"
jaxb:version="1.0"
jaxb:extensionBindingPrefixes="xjc">
3)最后执行命令行 xjc -extension CDA.xsd 搞定
-extension : allow vendor extensions - do not strictly follow the
Compatibility Rules and App E.2 from the JAXB Spec