我一直在尝试从服务器获取XML文件并查看日期以尝试查看我的日期值是否与其中一个xml日期值相同。我有点卡住,因为我不确定在解析xml文件后该怎么做。我的xml文件和脚本的代码如下所示;
XML文件:
<holidays>
<holiday type="fixed" name="New year's day" date="01/Jan"
duration_seconds="1d"/>
<holiday type="fixed" name="Christmas day" date="25/Dec"
duration_seconds="1d"/>
<holiday type="fixed" name="Boxing day" date="26/Dec"
duration_seconds="1d"/>
<holiday type="floating" name="Family Day" date="20/Feb/17"
duration_seconds="1d"/>
<holiday type="floating" name="Good Friday" date="14/Apr/17"
duration_seconds="1d"/>
<holiday type="floating" name="CENGN Easter day off (only in 2017)"
date="17/Apr/17" duration_seconds="1d"/>
<holiday type="floating" name="Victoria Day" date="22/May/17"
duration_seconds="1d"/>
<holiday type="floating" name="Canada day" date="03/Jul/17"
duration_seconds="1d"/>
<holiday type="floating" name="Civic Holiday" date="07/Aug/17"
duration_seconds="1d"/>
<holiday type="floating" name="Labor day" date="04/Sep/17"
duration_seconds="1d"/>
<holiday type="floating" name="Thanksgiving day" date="09/Oct/17"
duration_seconds="1d"/>
</holidays>
这是我尝试使用的脚本。
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl;
import com.onresolve.scriptrunner.runner.customisers.PluginModule;
import com.onresolve.scriptrunner.runner.customisers.WithPlugin;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import java.lang.Object
import com.atlassian.jira.issue.worklog.WorklogImpl2
import java.text.SimpleDateFormat
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.worklog.DefaultWorklogManager
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.worklog.Worklog
import com.atlassian.jira.datetime.LocalDate
import org.apache.commons.lang.RandomStringUtils
import groovy.xml.MarkupBuilder
import groovy.util.*
import groovy.xml.MarkupBuilder
def componentManager = ComponentManager.getInstance()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfend = customFieldManager.getCustomFieldObjectByName("End Date")
def cfstart = customFieldManager.getCustomFieldObjectByName("Start
Date")
def cfdays = customFieldManager.getCustomFieldObjectByName("Used
vacation days")
def reporter = issue.reporter.name
def worklogManager = ComponentAccessor.getWorklogManager();
String f = new File('/var/atlassian/application-
data/jira_7.3.1/import/holidays.xml')
def list = new XmlParser().parse(f)
def xml = new XmlSlurper().parse(f)
//NEED HELP AFTER THIS LINE ********************************
def holiday = xml.depthFirst().findAll {it.holiday}
xml.holiday.date() == 2
def d =((issue.getCustomFieldValue(cfstart) as Date) + i).getDate()
def m = ((issue.getCustomFieldValue(cfstart) as Date) + i).getMonth()
return 0;
这只是我脚本的一部分,我想知道是否有一个很好的方法从xml文件中获取日期并将其与发布日期和发布月份进行比较。我无法查找与我的
类似的xml文件示例