Java jaxb anyelement名称空间any而不是other

Java jaxb anyelement名称空间any而不是other,java,jaxb,Java,Jaxb,我有一个javajaxb注释类 @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement() public class xmlDoc<T> { @XmlMixed @XmlAnyElement(lax=false) protected T content; public T getContent() { return this.content; } public void setContent(T

我有一个javajaxb注释类

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement()
public class xmlDoc<T> {
@XmlMixed
@XmlAnyElement(lax=false)
   protected T content;
   public T getContent() {
      return this.content;
   }
   public void setContent(T t) {
        this.content = t;
   }
}
@xmlacessortype(xmlacesstype.FIELD)
@XmlRootElement()
公共类xmlDoc{
@混合
@xmlanyement(lax=false)
保护T含量;
公共T getContent(){
返回此.content;
}
公共内容(T){
这个。内容=t;
}
}
当我使用jaxb生成xml模式时,我得到以下输出

<xs:complexType mixed="true" name="xmlDoc">
    <xs:sequence>
      <xs:any namespace="##other" processContents="skip"/>
    </xs:sequence>
  </xs:complexType>

jaxb中是否有任何注释参数,我可以使用它控制任何元素类型的名称空间。我需要任何的,而不是其他的。
这可能吗?

没有参数控制细节的输出。但是,如果我将名称空间的参数修改为##any,则生成wsdl时,它将允许转换为现有数据类型并根据需要工作。

没有参数控制详细信息的输出。但是当生成wsdl时,如果我将名称空间的参数修改为##any,它将允许转换为现有数据类型并根据需要工作。

如我在上面的评论中所述,我查看了参考实现的源代码,发现它只是为any元素编写了硬编码

因此,我现在用以下方法将文件生成后的###other替换为#any

  private static void fixNamespaceOfAnyElementsFor(final File xsdFile) throws IOException, FileNotFoundException {
    final File tempFile = File.createTempFile("your_prefix", ".tmp");
    Files.move(xsdFile.toPath(), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    try (final BufferedWriter writer = Files.newBufferedWriter(xsdFile.toPath())) {
      try (final Stream<String> lines = Files.lines(tempFile.toPath())) {
        lines.map(line -> line.replace("namespace=\"##other\"", "namespace=\"##any\""))
            .forEach(line -> {
              try {
                writer.write(line);
                writer.newLine();
              } catch (final IOException e) {
                throw new UncheckedIOException(e);
              }
            });
      }
    }
    Files.delete(tempFile.toPath());
  }
private static void fixNamespaceOfAyelementsfor(最终文件xsdFile)引发IOException、FileNotFoundException{
final File tempFile=File.createTempFile(“您的_前缀“,”.tmp”);
move(xsdFile.toPath()、tempFile.toPath()、StandardCopyOption.REPLACE_EXISTING);
try(final BufferedWriter writer=Files.newBufferedWriter(xsdFile.toPath())){
try(final Stream lines=Files.lines(tempFile.toPath())){
line.map(line->line.replace(“名称空间=\”、“名称空间=\”、“任何名称”))
.forEach(行->{
试一试{
作者:写(行);
writer.newLine();
}捕获(最终IOE例外){
抛出新的未选中异常(e);
}
});
}
}
delete(tempFile.toPath());
}
它基本上会将文件移动到一个临时文件夹,这样我就可以在原始位置重写它,替换属性值。完成后,临时文件将被删除


注意:首先我研究了DOM和Stax的解决方案,但它们都弄乱了生成器的原始格式(漂亮的打印)。由于我将生成的XSD提交给git,并且每一代都需要一致的格式,所以我决定采用简单的逐行解决方案。

正如我在上面的评论中所提到的,我查看了参考实现的源代码,发现它只是为any元素编写了硬编码的##other

因此,我现在用以下方法将文件生成后的###other替换为#any

  private static void fixNamespaceOfAnyElementsFor(final File xsdFile) throws IOException, FileNotFoundException {
    final File tempFile = File.createTempFile("your_prefix", ".tmp");
    Files.move(xsdFile.toPath(), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
    try (final BufferedWriter writer = Files.newBufferedWriter(xsdFile.toPath())) {
      try (final Stream<String> lines = Files.lines(tempFile.toPath())) {
        lines.map(line -> line.replace("namespace=\"##other\"", "namespace=\"##any\""))
            .forEach(line -> {
              try {
                writer.write(line);
                writer.newLine();
              } catch (final IOException e) {
                throw new UncheckedIOException(e);
              }
            });
      }
    }
    Files.delete(tempFile.toPath());
  }
private static void fixNamespaceOfAyelementsfor(最终文件xsdFile)引发IOException、FileNotFoundException{
final File tempFile=File.createTempFile(“您的_前缀“,”.tmp”);
move(xsdFile.toPath()、tempFile.toPath()、StandardCopyOption.REPLACE_EXISTING);
try(final BufferedWriter writer=Files.newBufferedWriter(xsdFile.toPath())){
try(final Stream lines=Files.lines(tempFile.toPath())){
line.map(line->line.replace(“名称空间=\”、“名称空间=\”、“任何名称”))
.forEach(行->{
试一试{
作者:写(行);
writer.newLine();
}捕获(最终IOE例外){
抛出新的未选中异常(e);
}
});
}
}
delete(tempFile.toPath());
}
它基本上会将文件移动到一个临时文件夹,这样我就可以在原始位置重写它,替换属性值。完成后,临时文件将被删除


注意:首先我研究了DOM和Stax的解决方案,但它们都弄乱了生成器的原始格式(漂亮的打印)。由于我要将生成的XSD提交到git,并且每一代都需要一致的格式,所以我决定采用简单的逐行解决方案。

这是否意味着,您要在每一代之后手动更改生成的XSD文件?这不是问题的真正解决办法,对吗?您是否也在使用
JAXBContext.generateSchema()
生成文件?我需要依靠模式生成器输出##any。如果你真的能解决它,请分享你所做的,或者只是再次打开这个问题让其他人回答。好的,我查看了参考实现的源代码,发现它只是为any元素编写了##其他硬编码。所以我们无能为力。我将尝试编写一个小过程,简单地用###any替换##other,这样我就不必在每一代上手动执行此操作。这是否意味着在每一代之后手动更改生成的xsd文件?这不是问题的真正解决办法,对吗?您是否也在使用
JAXBContext.generateSchema()
生成文件?我需要依靠模式生成器输出##any。如果你真的能解决它,请分享你所做的,或者只是再次打开这个问题让其他人回答。好的,我查看了参考实现的源代码,发现它只是为any元素编写了##其他硬编码。所以我们无能为力。我将尝试编写一个小过程,简单地用###any替换##other,这样就不必在每一代中手动执行此操作。