How do I change Castor mapping to remove the "xmlns: xsi" and "xsi: type" attributes from an XML output element?

How to change castor display

<?xml version="1.0"?> <!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN" "http://castor.org/mapping.dtd"> <mapping> <class name="java.util.ArrayList" auto-complete="true"> <map-to xml="ArrayList" /> </class> <class name="com.db.spgit.abstrack.ws.response.UserResponse"> <map-to xml="UserResponse" /> <field name="id" type="java.lang.String"> <bind-xml name="id" node="element" /> </field> <field name="deleted" type="boolean"> <bind-xml name="deleted" node="element" /> </field> <field name="name" type="java.lang.String"> <bind-xml name="name" node="element" /> </field> <field name="typeId" type="java.lang.Integer"> <bind-xml name="typeId" node="element" /> </field> <field name="regionId" type="java.lang.Integer"> <bind-xml name="regionId" node="element" /> </field> <field name="regionName" type="java.lang.String"> <bind-xml name="regionName" node="element" /> </field> </class> </mapping> 

to suppress xmlns:xsi and xsi:type attributes in XML output element? For example, instead of XML output

 <?xml version="1.0" encoding="UTF-8"?> <ArrayList> <UserResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="UserResponse"> <name>Tester</name> <typeId>1</typeId> <regionId>2</regionId> <regionName>US</regionName> </UserResponse> </ArrayList> 

I would prefer

 <?xml version="1.0" encoding="UTF-8"?> <ArrayList> <UserResponse> <name>Tester</name> <typeId>1</typeId> <regionId>2</regionId> <regionName>US</regionName> </UserResponse> </ArrayList> 

so the element name means xsi:type .

+4
source share
1 answer

Set the Castor Marshaller suppressXSIType property to false:

 Marshaller marshaller = new Marshaller(w); marshaller.setSuppressXSIType(true); 

See Configuring the Marshaller in Castor 1.3.1 Reference Documentation . (Note that in Table 1.10, the Marshaller properties only list the suppressNamespaces property, but the setSuppressNamespaces() and setSuppressXSIType() methods exist in the Marshaller class.)

+6
source

Source: https://habr.com/ru/post/1312345/


All Articles