2

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
  • 1,322
  • 6
  • 31
  • 42
  • do you have a package.java file in the same package folder as your Root.java object, or what JAXB annotations exist on your Root object? – Chris White Mar 22 '12 at 19:56
  • I have the package-info.java. I have updated the question to include it. maven-jaxb2 plugin generates these codes. Root.java has XmlAccessorType, XmlElement, XmlAttribute annotations. – arrehman Mar 22 '12 at 20:26

3 Answers3

1

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.

Chris White
  • 29,949
  • 4
  • 71
  • 93
  • 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... – arrehman Mar 22 '12 at 21:41
0

In order to automate the process you can just remove attribute targetNamespace from source xsd file

0

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.

arrehman
  • 1,322
  • 6
  • 31
  • 42