【问题标题】:How to read a XML file and removing some set of Tags如何读取 XML 文件并删除一组标签
【发布时间】:2013-12-21 11:26:09
【问题描述】:

我有一个 XML 文件,其中包含许多商店元素(请参见下面的示例),并且在商店中,它在异常元素中具有可用的日期和时间。 从这个 XML 文件中,我需要删除特定日期/日期的所有异常元素(例如,我需要在 12 月 16 日之后删除所有异常元素)。 我需要编写一个 java 程序来从特定日期删除这些异常元素并生成一个新文件。有人可以帮助我找到解决方案。

<stores>
<store>
<number>101</number>
<exception_hours>
<exception>
<date>
<![S[2013-12-16]]>
</date>
<hours>
<![S[09:00 to 22:00]]>
</hours>
</exception>
<exception>
<date>
<![S[2013-12-18]]>
</date>
<hours>
<![S[08:00 to 23:00]]>
</hours>
</exception>
<exception>
<date>
<![S[2013-12-20]]>
</date>
<hours>
<![S[08:00 to 23:00]]>
</hours>
</exception>
<exception>
<date>
<![S[2013-12-19]]>
</date>
<hours>
<![S[09:00 to 22:00]]>
</hours>
</exception>
<exception>
<date>
<![S[2013-12-15]]>
</date>
<hours>
<![S[10:00 to 19:00]]>
</hours>
</exception>
<exception>
<date>
<![S[2013-12-14]]>
</date>
<hours>
<![S[09:00 to 19:00]]>
</hours>
</exception>
</exception_hours>
</store>
<store>
.
.
.

</store>
</stores>

【问题讨论】:

标签: java


【解决方案1】:

我认为最简单的方法是使用JAXB(请参阅Use JAXB to create Object from XML String 以获得众多示例之一)。然后你可以用它做任何你需要的事情,只需对 Java 对象进行操作。

希望它有所帮助,您不要要求我们为您编写此代码 :-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-02
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 2013-06-01
    相关资源
    最近更新 更多