问题
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