如何更改Castor映射以删除"xmlns:xsi"和"xsi:type" XML输出中元素的属性? [英] How change Castor mapping to remove "xmlns:xsi" and "xsi:type" attributes from element in XML output?
问题描述
如何更改Castor映射
How do I change the Castor mapping
<?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>
抑制XML输出元素中的xmlns:xsi
和xsi:type
属性?例如,代替输出XML
to suppress the xmlns:xsi
and xsi:type
attributes in the element of the XML output? For example, instead of the output XML
<?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>
我希望
<?xml version="1.0" encoding="UTF-8"?>
<ArrayList>
<UserResponse>
<name>Tester</name>
<typeId>1</typeId>
<regionId>2</regionId>
<regionName>US</regionName>
</UserResponse>
</ArrayList>
,以使元素名称隐含xsi:type
.
推荐答案
将Castor Marshaller属性suppressXSIType
设置为false:
Set the Castor Marshaller property suppressXSIType
to false:
Marshaller marshaller = new Marshaller(w);
marshaller.setSuppressXSIType(true);
请参见中的配置编组器 href ="http://www.castor.org/reference/html/index.html" rel ="noreferrer"> Castor 1.3.1参考文档. (请注意,表1.10 Marshaller属性仅列出属性suppressNamespaces
,但是方法setSuppressNamespaces()
和setSuppressXSIType()
都存在于类Marshaller
中.)
See Configuring the Marshaller in the Castor 1.3.1 Reference Documentation. (Note that Table 1.10 Marshaller properties lists only property suppressNamespaces
, but methods setSuppressNamespaces()
and setSuppressXSIType()
both exist in class Marshaller
.)
这篇关于如何更改Castor映射以删除"xmlns:xsi"和"xsi:type" XML输出中元素的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!