There is currently no EclipseLink JAXB (MOXy) option to ignore namespaces. But there is an approach that you can use using the StAX parser.
Demo
You can create a StAX XMLStreamReader on an XML input that is not a namespace, and then disable MOXy.
package forum13416681; import javax.xml.bind.*; import javax.xml.stream.*; import javax.xml.transform.stream.StreamSource; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Foo.class); XMLInputFactory xif = XMLInputFactory.newFactory(); xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); StreamSource source = new StreamSource("src/forum13416681/input.xml"); XMLStreamReader xsr = xif.createXMLStreamReader(source); Unmarshaller unmarshaller = jc.createUnmarshaller(); Foo root = (Foo) unmarshaller.unmarshal(xsr); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(root, System.out); } }
Java Model (Foo)
package forum13416681; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Foo { private String bar; public String getBar() { return bar; } public void setBar(String bar) { this.bar = bar; } }
Input (input.xml)
The following is a simplified version of XML from your question. Note: this XML is not a proper namespace because it lacks a namespace declaration for the xsi prefix.
<?xml version="1.0" encoding="UTF-8"?> <foo xsi:schemaLocation="http://www.crossref.org/xschema/1.0 http://www.crossref.org/schema/unixref1.0.xsd"> <bar>Hello World</bar> </foo>
Exit
The following is the result of running the demo code.
<?xml version="1.0" encoding="UTF-8"?> <foo> <bar>Hello World</bar> </foo>
source share