问题
I am trying to set up transformation, using SlowCheetah, of a QuartzNet job configuration file. QuartzNet requires the xmlns attribute to be present on the job-scheduling-data node, but the presence of this attribute seems to stop SlowCheetah from running the transformations.
Simplified, this is what my scheduling config looks like:
<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
<schedule>
<job>
<name>Job1</name>
<group>Group1</group>
<description>Description</description>
<job-type>MySample.MyJob, MySample</job-type>
</job>
<trigger>
<cron>
<name>DefaultTrigger</name>
<job-name>Job1</job-name>
<job-group>Group1</job-group>
<cron-expression>0 0 4 * * ? *</cron-expression>
<time-zone>GMT Standard Time</time-zone>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
The config transformation looks like this:
<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" >
<cron-expression xdt:Transform="Replace" xdt:Locator="XPath(/job-scheduling-data/schedule/trigger/cron/cron-expression[../name/text() = 'DefaultTrigger'])">"##DAILY_SCHEDULE##</cron-expression>
</job-scheduling-data>
The transformation doesn't work unless I either remove
xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
from the original config file and the transformation file, or specify the namespace as, for example xmlns:ns1
. The problem with either of these two approaches is that Quartz requires xmlns="http://quartznet.sourceforge.net/JobSchedulingData"
to be present.
I have also tried using XPath expressions with local-name()
in an effort to ignore the namespace in the expression syntax, but to no avail.
Any ideas how to get around this?
回答1:
It seems to me that your XPath expression should be:
/job-scheduling-data/schedule/trigger/cron/cron-expression[../job-name/text() = 'Job1']
Since it was matching name
and not job-name
.
The scary namespace-ignoring XPath expression below should also work:
/*[local-name()='job-scheduling-data']/*[local-name()='schedule']/*[local-name()='trigger']/*[local-name()='cron']/*[local-name()='cron-expression'][../*[local-name()='job-name']/text() = 'Job1']
来源:https://stackoverflow.com/questions/24248270/slowcheetah-transformations-of-quartznet-config