JAXB Marshaller - How do I suppress xmlns namespace attributes?

10,609

Solution 1

The problem is resolved for now by removed all references to the namespace "http://www.fixprotocol.org/FIXML-4-4" from the generated jaxb2 code. This is crude. I was hoping for a more automated way.

Solution 2

So if you don't want the namespace information included, you could just remove the @XmlSchema annotation from package-info.java.

This somewhat breaks your automated build though as you said this is auto-generated from the maven plugin.

Suggest you look at the plugin options to see if you can remove this from the output, or you'll have to use some additional plugins to remove this line, or just delete the package-info.java all together.

Question - are you going to be passing this XML to a service that expects the namespace information to be included? I guess i'm interested in why you want to strip off the namespace info.

Share:
10,609
arrehman
Author by

arrehman

Updated on June 04, 2022

Comments

  • arrehman
    arrehman almost 2 years

    I generate XML using JAXB2 for an standalone java app that uses maven 3, jaxb2, FIXML schemas and maven-jaxb2-plugin. When I marshall the XML, the output root element has xmlns attributes in them. How do I remove this?

    From:

    <root ... xmlns="http://www.fixprotocol.org/FIXML-4-4">...</root>
    

    To:

    <root ... >...</root>
    

    Edit:

    package-info.java

    @javax.xml.bind.annotation.XmlSchema(namespace = "http://www.fixprotocol.org/FIXML-4-4", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
    package com.package;
    
  • arrehman
    arrehman about 12 years
    The external client, who we send the XML to specifically asked us to remove it. Not sure why. I will look into the option you mentioned or alternatives if any work...
  • icedek
    icedek about 11 years
    were you able to figure out a way to automate this?
  • arrehman
    arrehman about 11 years
    no, for me it wasn't worth it, it was a one time thing. so i did it manual. let me know if you find a solution.