How to store and retrieve objects using XML?

雨燕双飞 提交于 2019-12-11 16:17:35

问题


I have a class called Word with these four attributes: text, caseSensitive, matchSimilar and relevance.

I have 10 categories for these words: (allowDetermining,allowHigh,...,denyDetermining,denyHigh,etc.).

I want to be able to store new words on each categories or retrieve all words from some category. How can I do this.

I think the XML structure should be like this, but I don't know if I'm right:

<allowDetermining>
    <word>
        <text>Renato</text>
        <caseSensitive>true</caseSensitive>
        <matchSimilar>false</matchSimilar>
        <relevance>0.75</relevance>
     </word>
</allowDetermining>
<allowHigh>
    ...
</allowHigh>
...

At the moment, I'm using the XMLConfiguration class from Apache Commons Configuration. Any idea of how do this using it? And with another library?


回答1:


Is use of XML a requirement, or just your first idea? For persisting configuration data or working sets, JSON (data) or YAML (configuration) might make more sense and be bit easier to do as well. XML works better for its original use case (text markup), but for data-oriented stuff it is quickly falling out of favor, and for good reason.



来源:https://stackoverflow.com/questions/7434690/how-to-store-and-retrieve-objects-using-xml

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