xjc binding compiler configuration to add xmlns element to the package-info class?
You need to update you binding file like following. It will use eCH-0007 as prefix.
<?xml version="1.0"?>
<jxb:bindings version="1.0"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd
http://jaxb2-commons.dev.java.net/namespace-prefix http://java.net/projects/jaxb2-commons/sources/svn/content/namespace-prefix/trunk/src/main/resources/prefix-namespace-schema.xsd">
<jxb:bindings schemaLocation="eCH-0007-3-0.xsd">
<jxb:schemaBindings>
<jxb:package name="ch.ech.ech0007.v3" />
</jxb:schemaBindings>
<jxb:bindings>
<namespace:prefix name="eCH-0007" />
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
You can check complete example on this link Namespace-prefix.
Related videos on Youtube
Lovababu Padala
Developer, Freelancer and passionate about full JAVA Tech Stack. Currently work for Caterpillar India Engineering Solutions Pvt Ltd, at Bangalore. 12years of strong experience in Product development, great exposure to Telematics, Digital Media, ERP, Retail, Construction domains. Proficient in JAVA/J2EE, Micro services Architecture, Springboot, ReSTful Web Services, Spring framework, Hibernate ORM and DevOps. Hands-on experience in Python, GoLang, Apache Kafka stream processing, Spring Cloud frameworks, Docker containerization platform, ElasticSearch, Kubernetes, Testing frameworks like Junit, Mockito, Cucumber (Behavior Driven Development). Good exposure to cloud platforms AWS and Azure. Well versed at analyzing business requirements, evaluating client requirements, has hands-on experience in designing and implementing business models and functionalities and testing. Possesses excellent interpersonal, communication and analytical skills with demonstrated abilities in customer relationship management and team management.
Updated on September 15, 2022Comments
-
Lovababu Padala over 1 year
I am using Gradle to generate jaxb classes in my project. Every thing is working fine but while marshalling the jaxb object we are seeing different namespaces prefixes like ns1, ns2 .. randomly in the output xml. But we dont want this and want to specify specific namespace prefixes for each namespace. I checked here and found the link 15772478 saying we have to have package-info class with xmlns element, How can i say to xjc binding compiler to add xmlns element with prifixes and namespaceURI? below is the gradle configuration i have to generate Jaxb classes from schemas.
ant.taskdef(name: 'xjc', classname: 'com.sun.tools.xjc.XJCTask', classpath:configurations.jaxb.asPath) ant.jaxbTargetDir = jaxbTargetDir ant.xjc(destdir: '${jaxbTargetDir}', binding: 'xjc-bindings/bindings.jaxb', extension: true) { //arg(value: '-npa') arg(value: '-readOnly') arg(value: file('src/main/webapp/schemas/primary1.xsd')) arg(value: file('src/main/webapp/schemas/primary2.xsd')) arg(value: file('xjc-bindings/xjc-a.xsd')) arg(value: file('xjc-bindings/xjc-b.xsd')) }
sample package-info.java generated by xjc binding.
@XmlSchema(namespace = "urn:neustar:names:decedm:1.0") package biz.neustar.dece.xml.jaxb.decedm; import javax.xml.bind.annotation.XmlSchema;
I am expecting the package-info class like below.
@XmlSchema(namespace = "<someuri>", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED, xmlns={ @XmlNs(prefix="someprefix" , namespaceURI = "<some uri>") }) package biz.neustar.dece.xml.jaxb.core; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlSchema;
Can somebody please suggest me what is the configuration need to achieve this? I don't want to use NamespacePrefixMapper to specify the prefixes.
-
lexicore over 9 yearsSee also: stackoverflow.com/questions/25184035/…
-
-
Lovababu Padala over 9 yearsThis may works for one schema, but what if have multiple schemas and namespaces?
-
Zubair Ashraf over 9 yearsthen you can use this solution java.dzone.com/articles/jaxb-and-namespace-prefixes