Using JDK's JAXB without ns2 prefix

后端 未结 2 1337
伪装坚强ぢ
伪装坚强ぢ 2021-02-08 05:50

After having read all posts about this on Oracle forums, Stackoverflow, java.net I\'m finally posting here. I\'m using JAXB to create XML files but the problem is that it adds t

2条回答
  •  旧时难觅i
    2021-02-08 06:38

    Without the implementation of MOXy is not possible. JAXB if the preferred prefix is "", it generates a new one.

    I had the same problem in the past, and I configured each prefix for each package-info.java.

    NamespacePrefixMapper says in JAVADOC

    null if there's no prefered prefix for the namespace URI.
    In this case, the system will generate a prefix for you.
    
    Otherwise the system will try to use the returned prefix,
    but generally there's no guarantee if the prefix will be
    actually used or not.
    
    return "" to map this namespace URI to the default namespace.
    Again, there's no guarantee that this preference will be
    honored.
    
    If this method returns "" when requirePrefix=true, the return
    value will be ignored and the system will generate one"
    

    else if use package-info

    we know we can't bind to "", but we don't have any possible name at hand.
    generate it here to avoid this namespace to be bound to "".
    

    I hope I've given you all the answers about your question.

提交回复
热议问题