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

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

问题描述

我有一个名为 Word 的类,它具有以下四个属性:textcaseSensitivematchSimilar相关性.

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

目前,我正在使用 Apache Commons Configuration 中的 XMLConfiguration 类.知道如何使用它吗?和另一个图书馆?

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天全站免登陆