views:

223

answers:

3

The tool schemagen.exe generates xsd definitions from classes, e.g. the result is

<xs:schema elementFormDefault="qualified" version="1.0" targetNamespace="aa/bb" xmlns:a="aa/bbb" xmlns:tns="aa/bb" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

when I put in package-info.class on the package level:

@XmlSchema(namespace = "aa/bb", 
        elementFormDefault = XmlNsForm.QUALIFIED,
        xmlns = {@XmlNs(prefix="a", namespaceURI="aa/bb"),
           @XmlNs(prefix="xs",namespaceURI="http://www.w3.org/2001/XMLSchema")})

package aa.bb;
import javax.xml.bind.annotation.*;

The point is that now two prefixes exist: my preferred short one: a and the schemagen.exe automatically generated tns prefix. That is a pitty, because all generated types use the tns prefix, I would be glad if my own prefix was used in the generation without the tns one. Waht should I do?

+1  A: 

This is low-tech and error-prone, but why not open the XSD document in a text editor and use a few well-chosen global search-and-replace commands?

reinierpost
+1  A: 

Learn to like tns? It is a convention to use it to denote the target namespace in XML schemas after all.

Andy
A: 

At runtime, you can use the JAXB NamespacePrefixMapper to change the generated prefixes for your chosen ones.

skaffman