我正在尝试为ECMA-376 v5模式生成类,但无法通过绑定自定义修复两个元素的冲突,即它会引发[ERROR] Two declarations cause a collision in the ObjectFactory class
错误。
要自己尝试,只需将下面的 ant 构建和绑定文件放在一个目录中,然后调用“ant”来设置和生成类。
如果取消注释 ooxml.xjb 中的“Fixme”行,生成将成功,但查看src/org/openxmlformats/schemas/wordprocessingml/_2006/main/ObjectFactory.java
“Fixme”元素的生成方式不同,可能没有意义。因此,也许将其用作修复的提示。
我猜这个错误是由...中的多个"r"
元素/引用引起的:
wml.xsd->CT_RunTrackChange->EG_ContentRunContent->r
wml.xsd->CT_RunTrackChange->shared-math.xsd->EG_OMathMathElements->r
shared-math.xsd->EG_OMathElements->EG_OMathMathElements->r
shared-math.xsd->EG_OMathElements->wml.xsd->EG_PContentMath->EG_ContentRunContentBase->EG_RunLevelElts->EG_MathContent->shared-math.xsd->oMath->CT_OMath->EG_OMathElements...
(见 3/4)
尽管有关于 SO 的参考资料,这-XautoNameResolution
会有所帮助,但这在我的情况下似乎是徒劳的。
如果没有任何帮助,我可能会在生成后搜索/替换 fixme 令牌,但我想正确的绑定说明并不遥远......
如果你想知道我为什么使用 Moxy。这是 Apache POI 的原型,Moxy 适用于android 转换和许可证兼容- 无论如何,我的目标是保留 XML 信息集的解决方案。
构建.xml:<project name="ECMA v5 xjc" default="doit" basedir=".">
<!-- the repository to download jars from -->
<property name="repository.m2" value="https://repo1.maven.org"/>
<property name="jaxb-dir" location="lib"/>
<property name="dist.jaxb-xjc.url" value="${repository.m2}/maven2/com/sun/xml/bind/jaxb-xjc/2.3.0/jaxb-xjc-2.3.0.jar"/>
<property name="dist.jaxb-xjc.jar" value="${jaxb-dir}/jaxb-xjc-2.3.0.jar"/>
<property name="dist.jaxb-core.url" value="${repository.m2}/maven2/com/sun/xml/bind/jaxb-core/2.3.0/jaxb-core-2.3.0.jar"/>
<property name="dist.jaxb-core.jar" value="${jaxb-dir}/jaxb-core-2.3.0.jar"/>
<property name="dist.jaxb-api.url" value="${repository.m2}/maven2/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar"/>
<property name="dist.jaxb-api.jar" value="${jaxb-dir}/api/jaxb-api-2.3.0.jar"/>
<property name="dist.eclipselink.url" value="${repository.m2}/maven2/org/eclipse/persistence/eclipselink/2.7.0/eclipselink-2.7.0.jar"/>
<property name="dist.eclipselink.jar" value="${jaxb-dir}/eclipselink-2.7.0.jar"/>
<property name="dist.moxy.url" value="${repository.m2}/maven2/org/eclipse/persistence/org.eclipse.persistence.moxy/2.7.0/org.eclipse.persistence.moxy-2.7.0.jar"/>
<property name="dist.moxy.jar" value="${jaxb-dir}/org.eclipse.persistence.moxy-2.7.0.jar"/>
<property name="dist.ooxml_v5.url" value="https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-376,%20Fifth%20Edition,%20Part%204%20-%20Transitional%20Migration%20Features.zip"/>
<property name="dist.ooxml_v5.jar" value="${jaxb-dir}/ooxml_v5-all.zip"/>
<property name="dist.xmlxsd.url" value="http://www.w3.org/2001/03/xml.xsd"/>
<property name="dist.xmlxsd.xsd" value="${jaxb-dir}/xml.xsd"/>
<macrodef name="downloadfile">
<attribute name="src"/>
<attribute name="dest"/>
<sequential>
<get src="@{src}" dest="@{dest}" skipexisting="true"/>
</sequential>
</macrodef>
<target name="doit">
<mkdir dir="src"/>
<mkdir dir="${jaxb-dir}/api"/>
<mkdir dir="${jaxb-dir}/ooxml_v5"/>
<mkdir dir="${jaxb-dir}/episodes_v5"/>
<downloadfile src="${dist.jaxb-xjc.url}" dest="${dist.jaxb-xjc.jar}"/>
<downloadfile src="${dist.jaxb-core.url}" dest="${dist.jaxb-core.jar}"/>
<downloadfile src="${dist.jaxb-api.url}" dest="${dist.jaxb-api.jar}"/>
<downloadfile src="${dist.eclipselink.url}" dest="${dist.eclipselink.jar}"/>
<downloadfile src="${dist.moxy.url}" dest="${dist.moxy.jar}"/>
<downloadfile src="${dist.ooxml_v5.url}" dest="${dist.ooxml_v5.jar}"/>
<downloadfile src="${dist.xmlxsd.url}" dest="${dist.xmlxsd.xsd}"/>
<unzip dest="${jaxb-dir}" src="${dist.ooxml_v5.jar}">
<patternset>
<include name="OfficeOpenXML-XMLSchema-Transitional.zip"/>
</patternset>
<mergemapper to="ooxml_v5.zip"/>
</unzip>
<unzip dest="${jaxb-dir}/ooxml_v5" src="${jaxb-dir}/ooxml_v5.zip"/>
<!-- the DOCTYPE is causing problems with generating the schema classes -->
<copy tofile="${dist.xmlxsd.xsd}.edit" file="${dist.xmlxsd.xsd}">
<filterchain>
<linecontains negate="true">
<contains value="DOCTYPE"/>
</linecontains>
</filterchain>
</copy>
<move file="${dist.xmlxsd.xsd}.edit" tofile="${dist.xmlxsd.xsd}"/>
<java fork="true" classname="org.eclipse.persistence.jaxb.xjc.MOXyXJC">
<classpath>
<fileset dir="${jaxb-dir}" includes="*.jar"/>
</classpath>
<jvmarg value="-Djava.endorsed.dirs=${jaxb-dir}/api"/>
<!-- auto resolution is ignored ... -->
<arg value="-XautoNameResolution"/>
<arg value="-no-header"/>
<arg value="-extension"/>
<!--arg value="-verbose"/-->
<arg line="-episode ${jaxb-dir}/episodes_v5/step1.episodes"/>
<arg line="-b ooxml.xjb"/>
<arg line="-d src"/>
<arg value="${dist.xmlxsd.xsd}"/>
<arg value="${jaxb-dir}/ooxml_v5/shared-math.xsd"/>
<arg value="${jaxb-dir}/ooxml_v5/dml-main.xsd"/>
</java>
</target>
</project>
ooxml.xjb:
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<bindings version="2.1"
xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:math="http://schemas.openxmlformats.org/officeDocument/2006/math"
extensionBindingPrefixes="xjc">
<globalBindings generateIsSetMethod="true"/>
<bindings scd="x-schema::tns" xmlns:tns="http://schemas.openxmlformats.org/officeDocument/2006/math">
<bindings scd="~tns:CT_R/model::sequence">
<bindings scd="tns:rPr">
<factoryMethod name="rPrMath"/>
</bindings>
<bindings scd="model::choice/tns:t">
<factoryMethod name="tMath"/>
</bindings>
</bindings>
<!--bindings scd="group::math:EG_OMathMathElements/model::choice/math:r">
<property name="rMath1"/>
</bindings-->
</bindings>
<bindings scd="x-schema::tns" xmlns:tns="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing">
<bindings scd="~tns:CT_Anchor/model::sequence/tns:simplePos">
<property name="simplePosList"/>
</bindings>
</bindings>
<bindings scd="x-schema::tns" xmlns:tns="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<!--bindings scd="~tns:CT_RunTrackChange/model::choice/group::math:EG_OMathMathElements/model::choice/math:r">
<class name="CTR" implClass="org.openxmlformats.schemas.officedocument._2006.math.CTR"/>
</bindings-->
<bindings scd="~tns:CT_RunTrackChange/model::choice/group::tns:EG_ContentRunContent/model::choice/tns:r">
<!--class name="FixmeR"/-->
</bindings>
</bindings>
</bindings>