首页 技术 正文
技术 2022年11月20日
0 收藏 807 点赞 3,161 浏览 3179 个字

xml文件:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!– This file contains job definitions in schema version 2.0 format –>
<job-scheduling-data xmlns=”http://quartznet.sourceforge.net/JobSchedulingData” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” version=”2.0″>
<processing-directives>
<overwrite-existing-data>true</overwrite-existing-data>
</processing-directives>
<schedule>

<trigger>
<cron>
<name>EmailBDOTrigger_2</name>
<group>EmailBDOTrigger_2</group>
<job-name>EmailBDOTriggerGroup_2</job-name>
<job-group>EmailBDOJob_2</job-group>
<cron-expression>1-2 1-3 1-3 * * ? </cron-expression>
</cron>
</trigger>

</schedule>
</job-scheduling-data>

后台:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Web;

namespace CronMaker
{
class XMLHandler 
{
string xmlPath = @”..\..\quartz_jobs.xml”;
//string xmlPath = HttpContext.Current.Server.MapPath(“~/quartz_jobs.xml”);

private String txtcorn;
public XMLHandler(String txtcorn)
{
this.txtcorn = txtcorn;
}

public void changNode()
{
//XmlTextReader tReader = new XmlTextReader(“\\quartz_jobs.xml”);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Normalize();
xmlDoc.Load(xmlPath);
//xml中有命名空间
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace(“mxh”, “http://quartznet.sourceforge.net/JobSchedulingData”);
string XPath = @”/mxh:job-scheduling-data/mxh:schedule/mxh:trigger/mxh:cron”;

XmlNodeList nodes = xmlDoc.SelectSingleNode(XPath, xnm).ChildNodes; 
foreach (XmlNode item in nodes)
{
// XmlElement element = item as XmlElement;
// Console.WriteLine(element.InnerText);
//if (element.Name == “cron-expression”)
// element.InnerText = txtcorn;
if (item.Name == “cron-expression”)
item.InnerText = txtcorn;
}
xmlDoc.Save(xmlPath);
}
public void addNode()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Normalize();
xmlDoc.Load(xmlPath);
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace(“mxh”, “http://quartznet.sourceforge.net/JobSchedulingData”);
string XPath = @”/mxh:job-scheduling-data/mxh:schedule”;
XmlNode root = xmlDoc.SelectSingleNode(XPath, xnm);

// XmlNode root = xmlDoc.SelectSingleNode(“job-scheduling-data/schedule”);

XmlElement trigger = xmlDoc.CreateElement(“trigger”,xmlDoc.DocumentElement.NamespaceURI);
XmlElement corn = xmlDoc.CreateElement(“cron”, xmlDoc.DocumentElement.NamespaceURI);
//加入name节点
XmlElement sub1 = xmlDoc.CreateElement(“name”, xmlDoc.DocumentElement.NamespaceURI);
sub1.InnerText = “EmailBDOTrigger_2”;
corn.AppendChild(sub1);
//group节点
XmlElement sub2 = xmlDoc.CreateElement(“group”, xmlDoc.DocumentElement.NamespaceURI);
sub2.InnerText = “EmailBDOTrigger_2”;
corn.AppendChild(sub2);
//job-name节点
XmlElement sub3 = xmlDoc.CreateElement(“job-name”, xmlDoc.DocumentElement.NamespaceURI);
sub3.InnerText = “EmailBDOTriggerGroup_2”;
corn.AppendChild(sub3);
//job-group节点
XmlElement sub4 = xmlDoc.CreateElement(“job-group”, xmlDoc.DocumentElement.NamespaceURI);
sub4.InnerText = “EmailBDOJob_2”;
corn.AppendChild(sub4);
//cron-expression节点
XmlElement sub5 = xmlDoc.CreateElement(“cron-expression”, xmlDoc.DocumentElement.NamespaceURI);
sub5.InnerText = txtcorn;
corn.AppendChild(sub5);

trigger.AppendChild(corn);
//问题所在:在AppendChildren,如果ParentNode是带有xmlns属性的,在新加节点时如果不指定xmlns或指定为空时,子节点将出现xmlns=””属性
//解决:不是没有为子节点指定命名空间,而是应该为其指定与父节点相同的命名空间
root.AppendChild(trigger);

xmlDoc.Save(xmlPath);
}

}
}

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,076
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894