Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.Map; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlSchema; public class Main { private static String getPrefix(final Package targetPackage, String namespaceURI) { String prefix; final Map<String, String> namespacePrefixes = new HashMap<String, String>(); if (targetPackage != null) { final XmlSchema xmlSchemaAnnotation = targetPackage.getAnnotation(XmlSchema.class); if (xmlSchemaAnnotation != null) { for (XmlNs xmlns : xmlSchemaAnnotation.xmlns()) { namespacePrefixes.put(xmlns.namespaceURI(), xmlns.prefix()); } } } prefix = namespacePrefixes.get(namespaceURI); return prefix; } }