如何使用XML存储和检索对象? [英] How to store and retrieve objects using XML?

查看:184
本文介绍了如何使用XML存储和检索对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类 Word 有这四个属性: text caseSensitive matchSimilar 相关性

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

我有这些词的10个类别:( allowDetermining allowHigh ,..., denyDetermining denyHigh 等)。

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.

我认为XML结构应该是这样的,但我不知道我是否是对的:

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>
...

目前,我使用 XMLConfiguration class Apache Commons Configuration 。任何想法如何做到这一点使用它?和另一个库?

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?

推荐答案

使用XML是一个要求,还是仅仅是你的第一个想法?对于持久的配置数据或工作集,JSON(数据)或YAML(配置)可能更有意义,也更容易做到。 XML对于其原始用例(文本标记)效果更好,但对于面向数据的内容,它很快就失去了支持,这是很好的原因。

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.

这篇关于如何使用XML存储和检索对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆