简体   繁体   English

如何读取XML文件并删除一些标签集

[英]How to read a XML file and removing some set of Tags

I have a XML file having number of store elements(see example below) and in store it have its date and time of availability in exception elements. 我有一个具有多个存储元素的XML文件(请参见下面的示例),并且在存储中它在异常元素中具有其可用的日期和时间。 from this XML file I need to remove all the exception elements from a particular day/date(eg I need to delete all the exception elements after 16th Dec). 从这个XML文件中,我需要删除特定日期/日期中的所有异常元素(例如,我需要在12月16日之后删除所有异常元素)。 I need to write a java program to delete these exception elements from a particular date and generate a new file. 我需要编写一个Java程序来从特定日期删除这些异常元素并生成一个新文件。 Can some one please help me in finding the solution. 有人可以帮我找到解决方案吗?

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

I think the easiest way would be to use JAXB (see Use JAXB to create Object from XML String for one of many examples). 我认为最简单的方法是使用JAXB (有关许多示例之一,请参见使用JAXB从XML字符串创建对象 )。 Then you may do whatever you need with this, just operating on Java objects. 然后,您可以执行此操作,只需对Java对象进行操作即可。

Hope it helps and you don't ask us to write this code for you :-) 希望对您有所帮助,并且您不要要求我们为您编写此代码:-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM