Removing XML Java class attribute from SimpleXML code [duplicate]

送分小仙女□ 提交于 2020-01-17 08:47:07

问题


I am using SimpleXML to generate XML in a web service. But what I find with SimplexML is that the resulting code includes an attribute containing the underlying Java class type of the objects being represented.

So if I am using a Java ArrayList of a class of mine which is stored in the recentVisualisation element below, I get:

<User_Recent_Visualisations>
  <userNo>025347_17042011_1303046799093</userNo>
  <recentVisualisations class="java.util.ArrayList">
     <recent_Visualisation recentVisNo="9" recentVisName="fred">
        <createdDateTime>2013-06-28T14:09:17</createdDateTime>
    </recent_Visualisation>
  ...
</User_Recent_Visualisations>

Does anyone know if the attribute class="java.util.ArrayList"> can be suppressed?


回答1:


In your code if you are using List<Type> recentVisualisations for your items, Change it to ArrayList<Type> recentVisualisations (of course make sure this is what you want). The class attribute tells you what implementation of List is being used

UPDATE

You can also make it inline like mentioned here: Remove class= attribute

Basically

@Path("recentVisualisations")
@VisualisationList(inline=true)
<Access-Specifier>List<Type> recentVisualisations;


来源:https://stackoverflow.com/questions/17391184/removing-xml-java-class-attribute-from-simplexml-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!