Wednesday, July 13, 2011

JAXB Namespacing - including xmlns:xsi and xsi:schemalocation in namespace

How to include xmlns:xsi and xsi:schemalocation into the namespace while marshalling

1. Add the xmlns:xsi attributes in @XmlSchema in packge-info.java

  @java.xml.bind.annataion.XmlSchema (
       xmlns={ @javax.xml.bind.annataion.XMlNs(prefix="xsi" 
       namespaceURIU=http://www.vels.com/schemadef },
       namespace=http://ww.vels.com/2/,
      elementFormDefault = javax.xml.bind.annatation.XmlForm.QUALIFIED)
  package com.vels.test.schema;

2.Add the schmalocation uri JAXB_SCHEMA_LOCATION_URI in "marshallingproperties " of Jaxb2Marshaller class in spring-ws-servlet.xml

<bean id="marshaller" calss="org.springframework.oxm.jaxb.Jaxb2Marshaller">
     <property names="classesToBound">
             <list>
                    <value> com.vels.test.Sample.java </value>
              </list>
  </property>
//since its a static field property we need to use util:constant from spring dtd
 <property name="marshallingProperties">
         <map>
               <entry>
                      <key><util:constant static-field="javax.xml.bind.helpers.AbstractMarshallerImpl.JAXB_SCHEMA_LOCATION" /> </key>
<value> http://vels.com/vel.xsd </value>
</map>
...

your output xml looks like
<out xmlns="asdsd" xmlns:xsi="sdsdf" xsi:schemalocation=http://vels.com/vels.xsd>
....
</out>

No comments:

Post a Comment