How to easily convert an XML namespace to a Java package name?

I need to convert an XML namespace to a Java package name just like JAXB or XmlBeans.

For example, http:\www.widgetvendor.com\types\widgetTypes.xsd should be converted to com.widgetvendor.types.widgettypes

I can write my own function to perform this conversion, but I think this is a common task, and there should be utilities.
Can you name him?

+4
source share
3 answers

this link can help you http://forums.java.net/node/690286

but it’s better to write your own function where you can configure if there are some requirements in the future.

+1
source

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:

 /* Also available in the internal package space as part of the JDK */ import com.sun.xml.bind.api.impl.NameConverter; public static String convertToPackageName(String xmlNamespace) { NameConverter nameConverter = new NameConverter.Standard(); return nameConverter.toPackageName(xmlNamespace); } 
+1
source

This is not an ordinary task. It is best to program the function yourself.

(And before you ask ... No, I will not do this for you. Sorry.)

0
source

Source: https://habr.com/ru/post/1340153/


All Articles