質問

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;
役に立ちましたか?

解決 2

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.

他のヒント

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.

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top