JAXB:将具有属性的对象编组为重新声明名称空间的xml

JAXB:将具有属性的对象编组为重新声明名称空间的xml,jaxb,marshalling,xml-namespaces,Jaxb,Marshalling,Xml Namespaces,我有以下xml: <tag1 xmlns="myNamespace.com/#"> <insideTag myAttribute="5"> some text </insideTag> </tag1> 但编组后,它变成了这样: <tag1 xmlns="myNamespace.com"> <insideTag xmlns:ns1="myNamespace.com/#" xmlns="" m

我有以下xml:

<tag1 xmlns="myNamespace.com/#">
    <insideTag myAttribute="5">
        some text
    </insideTag>
</tag1>
但编组后,它变成了这样:

<tag1 xmlns="myNamespace.com">
    <insideTag xmlns:ns1="myNamespace.com/#" xmlns="" myAttribute="5">
        some text
    </insideTag>
</tag1>
我知道,这几乎是一样的,但我真的需要xml像第一个一样

我没有这个xml的xsd。实际上,该xml被解析为org.w3c.dom.Element,添加到ObjectType xsd和下面的类简化实现中,然后对该ObjectType进行编组。 如果这很重要的话,我使用的是名称空间前缀xmapper。 xsd注意attributeFormDefault是未设置的

<schema xmlns="http://www.w3.org/2001/XMLSchema" version="0.1"
  xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
  targetNamespace="http://www.w3.org/2000/09/xmldsig#"
  elementFormDefault="qualified">

    <complexType name="ObjectType" mixed="true">
        <sequence minOccurs="0" maxOccurs="unbounded">
            <any namespace="##any" processContents="lax"/>
        </sequence>
    </complexType>
</schema>
类别:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "ObjectType", namespace = "http://www.w3.org/2000/09/xmldsig#",
   propOrder = { "content" })
public class ObjectType{
    @XmlMixed
    @XmlAnyElement(lax = true)
    protected List<Object> content;

    public List<Object> getContent() {
        if (content == null) {
            content = new ArrayList<Object>();
        }
        return this.content;
    }
}
所以。。。有人知道怎么解决这个问题吗? 顺便说一句,解决方案也必须与jaxb-impl-2.1.4配合使用


谢谢大家的帮助。

为了避免不必要的名称传递,您需要像这样在ObjectFactory类中注册:

@XmlElementDecl(name="CurrencyPayTypeCode") 
public JAXBElement<OLILUMEASUNITS> createCurrencyPayTypeCode(OLILUMEASUNITS elem) {
                return new JAXBElement<OLILUMEASUNITS>(new QName("OLILUMEASUNITS"), OLILUMEASUNITS.class, elem); 
}
其中:

CurrencyPayTypeCode-insideTag的名称 OLILUMEASUNITS-一个可以将此标记解组的类