我正在尝试为ECMA-376 v5架构生成类,但无法通过bindings customization修复两个元素的冲突,即它会抛出[ERROR] Two declarations cause a collision in the ObjectFactory class
错误。
要自己尝试一下,只需将下面的ant build和bindings文件放在一个目录中,然后调用“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)虽然有references on SO,但-XautoNameResolution
会有所帮助,但在我看来这似乎是徒劳的。
如果没有任何帮助,我可能会在生成后搜索/替换fixme令牌,但我想正确的绑定说明并不遥远......
如果你想知道为什么我使用Moxy。这是Apache POI的原型,而Moxy适用于android-conversion和license compatible - 无论如何我都希望找到一个保留XML信息集的解决方案。
build.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>