Skip to main content
This revision made May 23, 2012 13:03, by Manuel Siggen

namespace-prefix


The namespace-prefix plugin adds javax.xml.bind.annotation.XmlNs annotations to package-info.java file according to an external mapping file. Those annotations associate namespace prefixes with XML namespace URIs.

Exemple


The following package-info.java is generated automatically with the XmlNs annotation :

    @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.ech.ch/xmlns/eCH-0007/3", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns = {
        @javax.xml.bind.annotation.XmlNs(namespaceURI = "http://www.ech.ch/xmlns/eCH-0007/3", prefix = "eCH-0007")
    })
    package ch.ech.ech0007.v3;

And then, Jaxb2 will build Xml structure that look like this :

    <?xml version="1.0" encoding="UTF-8"?>
    <eCH-0007:municipalityRoot xmlns:eCH-0007="http://www.ech.ch/xmlns/eCH-0007/3">
        <eCH-0007:swissMunicipalityType>
            ...
        </eCH-0007:swissMunicipalityType>
    </eCH-0007:municipalityRoot>

Instead of the default prefix numbering scheme :

    <?xml version="1.0" encoding="UTF-8"?>
    <ns1:municipalityRoot xmlns:ns1="http://www.ech.ch/xmlns/eCH-0007/3">
        <ns1:swissMunicipalityType>
            ...
        </ns1:swissMunicipalityType>
    </ns1:municipalityRoot>

Usage


Example's configuration with the maven-jaxb2-plugin :

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.8.0</version>
    <configuration>
        <schemaDirectory>src/main/resources</schemaDirectory>
        <catalog>src/main/resources/catalog.xml</catalog>
        <schemaIncludes>
            <include>*.xsd</include>
        </schemaIncludes>
        <bindingDirectory>src/main/resources</bindingDirectory>
        <bindingIncludes>
            <include>bindings.xml</include>
        </bindingIncludes>
        <args>
            <arg>-extension</arg>
            <arg>-Xnamespace-prefix</arg>
            <arg>-Xnamespace-prefix-file:mapping.txt</arg>
        </args>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.jvnet.jaxb2_commons</groupId>
            <artifactId>jaxb2-namespace-prefix</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</plugin>

Using the following mapping.txt file :

    [ch.ech.ech0007.v3]
    http://www.ech.ch/xmlns/eCH-0007/3=eCH-0007

Format of the mapping file is :

    [fully.qualified.package.name]
    XML-namespace-URI=prefix

More than one package can be specified, and more than one namespace can be specified per package.

Difference compared to previous revision
<span> == Usage Example's configuration with the maven-jaxb2-plugin :<span style="text-decoration:line-through;color:red"> </span>=namespace-prefix The ''namespace-prefix'' plugin adds ''javax.xml.bind.annotation.XmlNs'' annotations to ''package-info.java'' file according to an external mapping file. Those annotations associate namespace prefixes with XML namespace URIs. ... Example's configuration with the maven-jaxb2-plugin : <p<span style="text-decoration:underline;color:green">re> <p</span><plugin> <span style="text-decoration:line-through;color:red"> </span><groupId>org.jvnet.jaxb2.maven2</groupId> <span style="text-decoration:line-through;color:red"> </span><artifactId>maven-jaxb2-plugin</artifactId> <span style="text-decoration:line-through;color:red"> </span><version>0.8.0</version> <span style="text-decoration:line-through;color:red"> </span><configuration> <span style="text-decoration:line-through;color:red"> </span><schemaDirectory>src/main/resources</schemaDirectory> <span style="text-decoration:line-through;color:red"> </span><catalog>src/main/resources/catalog.xml</catalog> <span style="text-decoration:line-through;color:red"> </span><schemaIncludes> <span style="text-decoration:line-through;color:red"> </span><include>*.xsd</include> <span style="text-decoration:line-through;color:red"> </span></schemaIncludes> <span style="text-decoration:line-through;color:red"> </span><bindingDirectory>src/main/resources</bindingDirectory> <span style="text-decoration:line-through;color:red"> </span><bindingIncludes> <span style="text-decoration:line-through;color:red"> </span><include>bindings.xml</include> <span style="text-decoration:line-through;color:red"> </span></bindingIncludes> <span style="text-decoration:line-through;color:red"> </span><args> <span style="text-decoration:line-through;color:red"> </span><arg>-extension</arg> <span style="text-decoration:line-through;color:red"> </span><arg>-Xnamespace-prefix</arg> <span style="text-decoration:line-through;color:red"> </span><arg>-Xnamespace-prefix-file:mapping.txt</arg> <span style="text-decoration:line-through;color:red"> </span></args> <span style="text-decoration:line-through;color:red"> </span></configuration> <span style="text-decoration:line-through;color:red"> </span><executions> <span style="text-decoration:line-through;color:red"> </span><execution> <span style="text-decoration:line-through;color:red"> </span><goals> <span style="text-decoration:line-through;color:red"> </span><goal>generate</goal> <span style="text-decoration:line-through;color:red"> </span></goals> <span style="text-decoration:line-through;color:red"> </span></execution> <span style="text-decoration:line-through;color:red"> </span></executions> <span style="text-decoration:line-through;color:red"> </span><dependencies> <span style="text-decoration:line-through;color:red"> </span><dependency> <span style="text-decoration:line-through;color:red"> </span><groupId>org.jvnet.jaxb2_commons</groupId> <span style="text-decoration:line-through;color:red"> </span><artifactId>jaxb2-namespace-prefix</artifactId> <span style="text-decoration:line-through;color:red"> </span><version>1.0-SNAPSHOT</version> <span style="text-decoration:line-through;color:red"> </span></dependency> <span style="text-decoration:line-through;color:red"> </span></dependencies> <span style="text-decoration:line-through;color:red"> </span>lugin> <groupId>org.jvnet.jaxb2.maven2</groupId> <artifactId>maven-jaxb2-plugin</artifactId> <version>0.8.0</version> ... <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </plugin><span style="text-decoration:underline;color:green"></pre></span> <span style="text-decoration:underline;color:green"> </span></plugin> Using the following ''mapping.txt'' file : [ch.ech.ech0007.v3] http://www.ech.ch/xmlns/eCH-0007/3=eCH-0007<span style="text-decoration:line-through;color:red">-3</span> Format of the mapping file is : <span>
 
 
Close
loading
Please Confirm
Close