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

  @java.xml.bind.annataion.XmlSchema (
       xmlns={ @javax.xml.bind.annataion.XMlNs(prefix="xsi" 
       namespaceURIU= },
      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">
                    <value> </value>
//since its a static field property we need to use util:constant from spring dtd
 <property name="marshallingProperties">
                      <key><util:constant static-field="javax.xml.bind.helpers.AbstractMarshallerImpl.JAXB_SCHEMA_LOCATION" /> </key>
<value> </value>

your output xml looks like
<out xmlns="asdsd" xmlns:xsi="sdsdf" xsi:schemalocation=>

No comments:

Post a Comment