Yes, there is an easy way to convert an XML namespace to a Java package name!
You can use the same class that JAXB internally uses to perform the operation, according to the JAXB 2.0 Final Release Specification (§D.5.1 Creating Java Code Rules: Mapping Namespace URIs from Rules).
I came across this publication since 2011 when looking for a standard class that will perform this operation. Unfortunately, snarky answers do not help anyone. Just in case, the next person will meet this question and would like to get a real answer, please see the code snippet below:
import com.sun.xml.bind.api.impl.NameConverter; public static String convertToPackageName(String xmlNamespace) { NameConverter nameConverter = new NameConverter.Standard(); return nameConverter.toPackageName(xmlNamespace); }
source share