0
我一直在試圖從服務器採取一個XML文件,並通過日期來嘗試,看看我的日期值是否與一個XML日期值。我有點卡住了,因爲我不確定在解析xml文件後該怎麼做。我的代碼爲xml文件和腳本可以在下面看到;使用groovy我需要分析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文件的示例
您希望與xml進行比較的腳本中的預期日期在哪裏? XML中的實際日期可以放在任何標籤中嗎? – Rao
感謝您的回覆,我剛剛看到您的評論。我實際上只是解決了它。您可以在此頁面上看到腳本。 https://stackoverflow.com/questions/44573965/not-reading-the-xml-nodes-properly/44574836#44574836 – Andrew
可能重複的[沒有正確讀取xml節點](https://stackoverflow.com/questions/ 44573965 /未讀的-XML節點,正確) – doelleri