如何去除使用xjc插件编译生成的XSD文件的根元素中的命名空间。我正在使用 JDK17 和 Jakarta。我只想将名称空间保留给子元素而不是根元素。
以下是我面临的问题。
预期生成的请求:
<Request xmlns="http://www.todo.com/services/" xmlns:ns2="http://www.todo.com/services/common/">
<RootElement1>
<ns2:ChildElement1>value1</ns2:ChildElement1>
<ns2:ChildElement2>value2</ns2:ChildElement2>
<ns2:ChildElement3>value3</ns2:ChildElement3>
<ns2:ChildElement4>value4</ns2:ChildElement4>
<ns2:ChildElement5>value5</ns2:ChildElement5>
</RootElement1>
<RootElement2>
<ns2:ChildElement1>value1</ns2:ChildElement1>
<ns2:ChildElement2>value2</ns2:ChildElement2>
<ns2:ChildElement3>value3</ns2:ChildElement3>
<ns2:ChildElement4>value4</ns2:ChildElement4>
</RootElement2>
</Request>
实际请求生成
<ns2:Request xmlns="http://www.todo.com/services/" xmlns:ns2="http://www.todo.com/services/common/">
<ns2:RootElement1>
<ChildElement1>value1</ChildElement1>
<ChildElement2>value2</ChildElement2>
<ChildElement3>value3</ChildElement3>
<ChildElement4>value4</ChildElement4>
<ChildElement5>value5</ChildElement5>
</ns2:RootElement1>
<ns2:RootElement2>
<ChildElement1>value1</ChildElement1>
<ChildElement2>value2</ChildElement2>
<ChildElement3>value3</ChildElement3>
<ChildElement4>value4</ChildElement4>
</ns2:RootElement2>
</ns2:Request>
My plugin settings looks like this in pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<addGeneratedAnnotation>false</addGeneratedAnnotation>
<xjbSources>
<xjbSource>src/main/schema/xsd/binding.xjb</xjbSource>
</xjbSources>
<sources>
<source>${project.basedir}/src/main/schema/xsd/common.xsd</source>
<source>${project.basedir}/src/main/schema/xsd/project.xsd</source>
</sources>
<outputDirectory>${project.build.directory}/generated-sources/ebg</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
我的 binding.xjb 看起来像这样
<?xml version="1.0" encoding="utf-8"?>
<jxb:bindings version="3.0" xmlns:xjc="https://jakarta.ee/xml/ns/jaxb/xjc"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
jxb:extensionBindingPrefixes="xjc" xmlns:jxb="https://jakarta.ee/xml/ns/jaxb"
xmlns:ifx="urn:ifxforum-org:XSD:1">
<jxb:bindings schemaLocation="project.xsd" node="/xs:schema" >
<jxb:schemaBindings>
<jxb:package name="com.sample.application.project">
</jxb:package>
</jxb:schemaBindings>
</jxb:bindings>
<jxb:bindings schemaLocation="common.xsd" node="/xs:schema">
<jxb:schemaBindings>
<jxb:package name="com.sample.application.common" />
</jxb:schemaBindings>
</jxb:bindings>
</jxb:bindings>